Updated description of AllowMassAssignmentMatcher.

This commit is contained in:
Jason Draper 2012-10-05 14:25:29 -04:00
parent e5914f75c1
commit a228e0e0ef
5 changed files with 32 additions and 4 deletions

View File

@ -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 File

@ -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 File

@ -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 File

@ -57,11 +57,21 @@ module Shoulda # :nodoc:
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 File

@ -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