Created
January 9, 2014 23:00
-
-
Save novohispano/8343750 to your computer and use it in GitHub Desktop.
Testing with Darryl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item < ActiveRecord::Base | |
has_many :order_items | |
has_many :orders, through: :order_items | |
validates :name, presence: true, uniqueness: true | |
validates :description, presence: true, uniqueness: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class ItemTest < ActiveSupport::TestCase | |
# test "the truth" do | |
# assert true | |
# end | |
test "it creates an item" do | |
result = Item.create | |
assert result | |
end | |
test "it an item has a name" do | |
result = Item.create(name: "hat") | |
assert_equal "hat", result.name | |
end | |
test "it an item has a description" do | |
result = Item.create(description: "tight") | |
assert_equal "tight", result.description | |
end | |
test "it doesn't create a valid item without a name" do | |
result = Item.create(description: "blue") | |
refute result.valid? | |
end | |
test "it doesn't create a valid item without a description" do | |
result = Item.create(name: "hammer") | |
refute result.save | |
end | |
test "it creates a valid item when given the correct attributes" do | |
result = Item.create(name: "pick", description: "sharp") | |
assert_equal "pick", result.name | |
assert_equal "sharp", result.description | |
assert result.valid? | |
end | |
test "it doesn't create a valid item when the name is repeated" do | |
Item.create(name: "pick", description: "sharp") | |
result = Item.create(name: "pick", description: "soft") | |
refute result.valid? | |
end | |
test "it doesn't create a valid item when the description is repeated" do | |
Item.create(name: "scissors", description: "sharp") | |
result = Item.create(name: "pick", description: "sharp") | |
refute result.valid? | |
end | |
test "it updates an item" do | |
item = Item.create(name: "puck", description: "round") | |
item.update_attributes(name: "ball", description: "red") | |
assert_equal "ball", item.name | |
assert_equal "red", item.description | |
assert item.valid? | |
end | |
end | |
# it creates an item | |
# it doesn't create an item when a validation prevents | |
# it deletes an item | |
# it updates an item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment