Skip to content

Commit

Permalink
refactoring tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed Apr 11, 2012
1 parent 4785633 commit 42617fd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -91,12 +91,12 @@ See the following examples:
it { must have_field(:name).of_type(String).with_default_value("me") }
it { wont have_field(:name).of_type(String).with_default_value("nodefault") }

it { must have_fields(:name, :nick) }
it { must have_fields(:name, :login) }
it { wont have_fields(:noexist, :noexistagain) }
it { must have_fields(:name, :nick).of_type(String) }
it { wont have_fields(:name, :nick).of_type(Integer) }
it { must have_fields(:name, :nick).with_default_value("me") }
it { must have_fields(:name, :nick).of_type(String).with_default_value("me") }
it { must have_fields(:name, :login).of_type(String) }
it { wont have_fields(:name, :login).of_type(Integer) }
it { must have_fields(:name, :login).with_default_value("me") }
it { must have_fields(:name, :login).of_type(String).with_default_value("me") }
end

### Validations Matchers
Expand All @@ -107,17 +107,17 @@ See the following examples:
it { must validate_presence_of(:name) }
it { wont validate_presence_of(:age) }

it { must validate_uniqueness_of(:nick) }
it { must validate_uniqueness_of(:login) }
it { wont validate_uniqueness_of(:name) }
it { must validate_uniqueness_of(:nick).case_insensitive }
it { wont validate_uniqueness_of(:code).case_insensitive }
it { must validate_uniqueness_of(:login).case_insensitive }
it { wont validate_uniqueness_of(:code).case_insensitive }

it { must validate_length_of(:password) }
it { wont validate_length_of(:code) }
it { must validate_length_of(:password).with_min(8) }
it { wont validate_length_of(:password).with_min(0) }
it { wont validate_length_of(:password).with_min(0) }
it { must validate_length_of(:password).with_minimum(8) }
it { wont validate_length_of(:password).with_minimum(0) }
it { wont validate_length_of(:password).with_minimum(0) }
it { must validate_length_of(:password).with_max(16) }
it { wont validate_length_of(:password).with_max(8) }
it { must validate_length_of(:password).with_maximum(16) }
Expand Down
10 changes: 5 additions & 5 deletions lib/mongoid-minitest/matchers/document/have_field.rb
Expand Up @@ -23,14 +23,14 @@ def matches?(klass)
@fields.each do |field|
if @klass.fields.include?(field)
error = ""
field = @klass.fields[field]
result_field = @klass.fields[field]

if @type && field.type != @type
error << " of type #{field.type}"
if @type && result_field.type != @type
error << " of type #{result_field.type}"
end

if !@default.nil? && !field.default.nil? && field.default != @default
error << " with default value of #{field.default}"
if !@default.nil? && !result_field.default.nil? && result_field.default != @default
error << " with default value of #{result_field.default}"
end

@errors << "field #{field.inspect << error}" if !error.blank?
Expand Down
10 changes: 5 additions & 5 deletions test/matchers/document_test.rb
Expand Up @@ -19,10 +19,10 @@
it { must have_field(:name).of_type(String).with_default_value("me") }
it { wont have_field(:name).of_type(String).with_default_value("nodefault") }

it { must have_fields(:name, :nick) }
it { must have_fields(:name, :login) }
it { wont have_fields(:noexist, :noexistagain) }
it { must have_fields(:name, :nick).of_type(String) }
it { wont have_fields(:name, :nick).of_type(Integer) }
it { must have_fields(:name, :nick).with_default_value("me") }
it { must have_fields(:name, :nick).of_type(String).with_default_value("me") }
it { must have_fields(:name, :login).of_type(String) }
it { wont have_fields(:name, :login).of_type(Integer) }
it { must have_fields(:name, :login).with_default_value("me") }
it { must have_fields(:name, :login).of_type(String).with_default_value("me") }
end
4 changes: 2 additions & 2 deletions test/matchers/validations_test.rb
Expand Up @@ -6,9 +6,9 @@
it { must validate_presence_of(:name) }
it { wont validate_presence_of(:age) }

it { must validate_uniqueness_of(:nick) }
it { must validate_uniqueness_of(:login) }
it { wont validate_uniqueness_of(:name) }
it { must validate_uniqueness_of(:nick).case_insensitive }
it { must validate_uniqueness_of(:login).case_insensitive }
it { wont validate_uniqueness_of(:code).case_insensitive }

it { must validate_length_of(:password) }
Expand Down
4 changes: 2 additions & 2 deletions test/models/person.rb
Expand Up @@ -6,13 +6,13 @@ class Person

field :code, type: String
field :name, type: String, default: "me"
field :nick, type: String, default: "me"
field :login, type: String, default: "me"
field :password, type: String
field :age, type: Integer

validates_presence_of(:name)
validates_uniqueness_of(:code)
validates_uniqueness_of(:nick, case_sensitive: false)
validates_uniqueness_of(:login, case_sensitive: false)

validates_length_of(:password, minimum: 8, maximum: 16)
end

0 comments on commit 42617fd

Please sign in to comment.