Skip to content
Browse files

Updated description of AllowMassAssignmentMatcher.

  • Loading branch information...
1 parent e5914f7 commit a228e0e0ef624e82197c41113d24c9bcce282fd6 @drapergeek drapergeek committed Oct 5, 2012
View
2 gemfiles/3.0.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs:
- shoulda-matchers (1.3.0)
+ shoulda-matchers (1.4.0)
activesupport (>= 3.0.0)
GEM
View
2 gemfiles/3.1.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs:
- shoulda-matchers (1.3.0)
+ shoulda-matchers (1.4.0)
activesupport (>= 3.0.0)
GEM
View
2 gemfiles/3.2.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: /Users/draper/Dropbox/Development/shoulda-matchers
specs:
- shoulda-matchers (1.3.0)
+ shoulda-matchers (1.4.0)
activesupport (>= 3.0.0)
GEM
View
12 lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb
@@ -57,11 +57,21 @@ def matches?(subject)
end
def description
- "allow mass assignment of #{@attribute}"
+ [base_description, role_description].compact.join(" ")
end
private
+ def base_description
+ "allow mass assignment of #{@attribute}"
+ end
+
+ def role_description
+ if role != :default
+ "as #{role}"
+ end
+ end
+
def role
@options[:role] || :default
end
View
18 spec/shoulda/active_model/allow_mass_assignment_of_matcher_spec.rb
@@ -1,6 +1,24 @@
require 'spec_helper'
describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do
+ describe "#description" do
+ context 'without a role' do
+ it 'includes the attribute name' do
+ matcher = Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher.new(:attr)
+ matcher.description.should eq("allow mass assignment of attr")
+ end
+ end
+
+ if active_model_3_1?
+ context 'with a role' do
+ it 'includes the attribute name and the role' do
+ matcher = Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher.new(:attr).as(:admin)
+ matcher.description.should eq("allow mass assignment of attr as admin")
+ end
+ end
+ end
+ end
+
context "an attribute that is blacklisted from mass-assignment" do
let(:model) do
define_model(:example, :attr => :string) do

0 comments on commit a228e0e

Please sign in to comment.
Something went wrong with that request. Please try again.