summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorluu <luuduong@gmail.com>2014-12-06 15:21:37 +0000
committerluu <luuduong@gmail.com>2014-12-06 15:21:37 +0000
commitf60ca93a327d773723f2ac7235331702256da656 (patch)
treeacff2a43acf7cc33baaaa5d2681ed3f7ca921eaf /spec
parentad658c4c7ba39191ed379ed73aa4a1b5a463be45 (diff)
add validation for asin and valid tool.
Diffstat (limited to 'spec')
-rw-r--r--spec/factories.rb7
-rw-r--r--spec/models/tool_spec.rb22
2 files changed, 23 insertions, 6 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index e1f30710..64309da3 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -76,4 +76,9 @@ FactoryGirl.define do
city "Calgary"
country "Canada"
end
-end
+
+ factory :tool do
+ name { Faker::Name.name }
+ asin { SecureRandom.uuid }
+ end
+end \ No newline at end of file
diff --git a/spec/models/tool_spec.rb b/spec/models/tool_spec.rb
index caf6ba94..db08b512 100644
--- a/spec/models/tool_spec.rb
+++ b/spec/models/tool_spec.rb
@@ -34,18 +34,30 @@ describe Tool do
end
context "#validation" do
+ let(:tool) { build(:tool) }
+
it "has to have a name" do
- tool = Tool.new
+ tool.name = nil
expect(tool).to_not be_valid
expect(tool.errors[:name]).to_not be_empty
end
it "name has to be unique" do
- Tool.create(name: 'blah')
-
- tool = Tool.new(name: 'blah')
- tool.valid?
+ create(:tool, name: 'blah')
+ tool.name = 'blah'
+
+ expect(tool).to_not be_valid
expect(tool.errors[:name]).to_not be_empty
end
+
+ it "has a ASIN number" do
+ tool.asin = nil
+ expect(tool).to_not be_valid
+ expect(tool.errors[:asin]).to_not be_empty
+ end
+
+ it "validates" do
+ expect(tool).to be_valid
+ end
end
end