accept_values_for 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -7,18 +7,17 @@ if defined?(ActiveRecord)
7
7
  # model.should accept_values_for(attribute, value1, value2 ...)
8
8
  # model.should_not accept_values_for(attribute, value1, value2 ...)
9
9
  #
10
- # model should be a valid ActiveRecord model
10
+ # model should be an instance of ActiveRecord::Base
11
11
  # attribute should be the model attribute name
12
12
  #
13
- # Use this if you want to check that model will be valid
14
- # with the given values for the given attribute
13
+ # Use this if you want to check that model should not have errors
14
+ # on specified attribute with the given values
15
15
  #
16
16
  # == Examples
17
17
  #
18
18
  # user.should accept_values_for(:email, "john@example.com", "lambda@gusiev.com")
19
19
  # user.should_not accept_values_for(:email, "invalid", nil, "a@b", "john@.com")
20
20
  #
21
- # IMPORTANT: passed model should be valid. Use fixtures or factories to create one.
22
21
  #
23
22
  def accept_values_for(attribute, *values)
24
23
  AcceptValuesFor.new(attribute, *values)
@@ -47,6 +46,20 @@ class AcceptValuesFor #:nodoc:
47
46
  return true
48
47
  end
49
48
 
49
+ def does_not_match?(model)
50
+ @model = model
51
+ return false unless model.is_a?(ActiveRecord::Base)
52
+ @values.each do |value|
53
+ model.send("#{@attribute}=", value)
54
+ model.valid?
55
+ unless model.errors.on(@attribute)
56
+ @failed_value = value
57
+ return false
58
+ end
59
+ end
60
+ return true
61
+ end
62
+
50
63
  def failure_message_for_should
51
64
  result = "expected #{@model.inspect} to accept value #{@failed_value.inspect} for #{@attribute.inspect}, but it was not\n"
52
65
  if @model.respond_to?(:errors) && ActiveRecord::Errors === @model.errors
@@ -7,4 +7,8 @@ describe "AcceptValuesFor" do
7
7
  it {should_not accept_values_for(:gender, "INVALID", nil)}
8
8
  it { should_not accept_values_for(:group, nil) }
9
9
  it { should accept_values_for(:group, Group.new) }
10
+
11
+ it "should have custom condition for should_not" do
12
+ accept_values_for(:gender, "INVALID", "MALE").does_not_match?(subject).should be_false
13
+ end
10
14
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bogdan Gusiev
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-14 00:00:00 +03:00
17
+ date: 2010-06-29 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency