README.md in mongoid-rspec-1.5.1 vs README.md in mongoid-rspec-1.5.3
- old
+ new
@@ -44,31 +44,45 @@
describe Record do
it { should belong_to(:user).as_inverse_of(:record) }
end
+Mass Assignment Matcher
+-
+ describe User do
+ it { should allow_mass_assignment_of(:login) }
+ it { should allow_mass_assignment_of(:email) }
+ it { should allow_mass_assignment_of(:age) }
+ it { should allow_mass_assignment_of(:password) }
+ it { should allow_mass_assignment_of(:password) }
+ it { should allow_mass_assignment_of(:role).as(:admin) }
+
+ it { should_not allow_mass_assignment_of(:role) }
+ end
+
Validation Matchers
-
describe Site do
it { should validate_presence_of(:name) }
it { should validate_uniqueness_of(:name) }
end
describe User do
- it { should validate_presence_of(:login) }
- it { should validate_uniqueness_of(:login).scoped_to(:site) }
- it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
- it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
- it { should validate_associated(:profile) }
- it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
- it { should validate_inclusion_of(:role).to_allow("admin", "member") }
- it { should validate_confirmation_of(:email) }
- it { should validate_presence_of(:age).on(:create, :update) }
- # The on matcher can take var args or an array. Validations do not fail if on is not specified.
- it { should validate_numericality_of(:age).on(:create, :update) }
- it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
- it { should validate_presence_of(:password).on(:create) }
+ it { should validate_presence_of(:login) }
+ it { should validate_uniqueness_of(:login).scoped_to(:site) }
+ it { should validate_uniqueness_of(:email).case_insensitive.with_message("is already taken") }
+ it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
+ it { should validate_associated(:profile) }
+ it { should validate_exclusion_of(:login).to_not_allow("super", "index", "edit") }
+ it { should validate_inclusion_of(:role).to_allow("admin", "member") }
+ it { should validate_confirmation_of(:email) }
+ it { should validate_presence_of(:age).on(:create, :update) }
+ it { should validate_numericality_of(:age).on(:create, :update) }
+ it { should validate_inclusion_of(:age).to_allow(23..42).on([:create, :update]) }
+ it { should validate_presence_of(:password).on(:create) }
+ it { should validate_presence_of(:provider_uid).on(:create) }
+ it { should validate_inclusion_of(:locale).to_allow([:en, :ru]) }
end
describe Article do
it { should validate_length_of(:title).within(8..16) }
end
@@ -85,18 +99,27 @@
describe Person do
# in order to be able to use the custom_validate matcher, the custom validator class (in this case SsnValidator)
# should redefine the kind method to return :custom, i.e. "def self.kind() :custom end"
it { should custom_validate(:ssn).with_validator(SsnValidator) }
end
+
+Index Matcher
+-
+ describe Article do
+ it { should have_index_for(published: 1) }
+ it { should have_index_for(title: 1).with_options(unique: true, background: true) }
+ end
+
+ describe Profile do
+ it { should have_index_for(first_name: 1, last_name: 1) }
+ end
+
Others
-
describe User do
it { should have_fields(:email, :login) }
it { should have_field(:active).of_type(Boolean).with_default_value_of(false) }
it { should have_fields(:birthdate, :registered_at).of_type(DateTime) }
-
- it { should have_index_for(:last_name) }
- it { should have_index_for(:email).with_options(:unique => true) }
it { should be_timestamped_document } # if you're declaring `include
Mongoid::Timestamps` or any of `include Mongoid::Timestamps::Created` and `Mongoid::Timestamps::Updated`
it { should be_timestamped_document.with(:created) }
it { should_not be_timestamped_document.with(:updated) }