Commit 8cd76a88 by Emil Sågfors

Add tests to demonstrate nil error in content type matcher failure message

Note: this is most likely not the way we want to test our matchers, but it
demonstrates the current issue.
parent 2c59f96f
...@@ -17,22 +17,26 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -17,22 +17,26 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
it "rejects a class with no validation" do it "rejects a class with no validation" do
expect(matcher).to_not accept(Dummy) expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it 'rejects a class when the validation fails' do it 'rejects a class when the validation fails' do
Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*} Dummy.validates_attachment_content_type :avatar, content_type: %r{audio/.*}
expect(matcher).to_not accept(Dummy) expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "accepts a class with a matching validation" do it "accepts a class with a matching validation" do
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*} Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
expect(matcher).to accept(Dummy) expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "accepts a class with other validations but matching types" do it "accepts a class with other validations but matching types" do
Dummy.validates_presence_of :title Dummy.validates_presence_of :title
Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*} Dummy.validates_attachment_content_type :avatar, content_type: %r{image/.*}
expect(matcher).to accept(Dummy) expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "accepts a class that matches and a matcher that only specifies 'allowing'" do it "accepts a class that matches and a matcher that only specifies 'allowing'" do
...@@ -40,6 +44,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -40,6 +44,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
matcher = plain_matcher.allowing(%w(image/png image/jpeg)) matcher = plain_matcher.allowing(%w(image/png image/jpeg))
expect(matcher).to accept(Dummy) expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "rejects a class that does not match and a matcher that only specifies 'allowing'" do it "rejects a class that does not match and a matcher that only specifies 'allowing'" do
...@@ -47,6 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -47,6 +52,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
matcher = plain_matcher.allowing(%w(image/png image/jpeg)) matcher = plain_matcher.allowing(%w(image/png image/jpeg))
expect(matcher).to_not accept(Dummy) expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "accepts a class that matches and a matcher that only specifies 'rejecting'" do it "accepts a class that matches and a matcher that only specifies 'rejecting'" do
...@@ -54,6 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -54,6 +60,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream)) matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
expect(matcher).to accept(Dummy) expect(matcher).to accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do it "rejects a class that does not match and a matcher that only specifies 'rejecting'" do
...@@ -61,6 +68,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -61,6 +68,7 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream)) matcher = plain_matcher.rejecting(%w(audio/mp3 application/octet-stream))
expect(matcher).to_not accept(Dummy) expect(matcher).to_not accept(Dummy)
expect { matcher.failure_message }.to_not raise_error
end end
context "using an :if to control the validation" do context "using an :if to control the validation" do
...@@ -75,12 +83,14 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do ...@@ -75,12 +83,14 @@ describe Paperclip::Shoulda::Matchers::ValidateAttachmentContentTypeMatcher do
dummy = Dummy.new dummy = Dummy.new
dummy.go = true dummy.go = true
expect(matcher).to accept(dummy) expect(matcher).to accept(dummy)
expect { matcher.failure_message }.to_not raise_error
end end
it "does not run the validation if the control is false" do it "does not run the validation if the control is false" do
dummy = Dummy.new dummy = Dummy.new
dummy.go = false dummy.go = false
expect(matcher).to_not accept(dummy) expect(matcher).to_not accept(dummy)
expect { matcher.failure_message }.to_not raise_error
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment