shoulda-matchers 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shoulda-matchers (1.4.0)
4
+ shoulda-matchers (1.4.1)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
data/NEWS.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v1.4.1
2
+ * Fixes an issue when used with Test::Unit on the allow value matcher.
3
+
4
+ * Fixes an issue with using ensure_inclusion_of(:attr) given an array of true or false values.
5
+
1
6
  # v1.4.0
2
7
 
3
8
  * Added `strict` option to validation matchers.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/draper/Dropbox/Development/shoulda-matchers
3
3
  specs:
4
- shoulda-matchers (1.3.0)
4
+ shoulda-matchers (1.4.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -38,16 +38,16 @@ GEM
38
38
  bundler
39
39
  rake
40
40
  arel (2.0.10)
41
- aruba (0.4.11)
42
- childprocess (>= 0.2.3)
41
+ aruba (0.5.0)
42
+ childprocess (= 0.2.3)
43
43
  cucumber (>= 1.1.1)
44
44
  ffi (>= 1.0.11)
45
- rspec (>= 2.7.0)
45
+ rspec-expectations (>= 2.7.0)
46
46
  bourne (1.1.2)
47
47
  mocha (= 0.10.5)
48
48
  builder (2.1.2)
49
- childprocess (0.3.5)
50
- ffi (~> 1.0, >= 1.0.6)
49
+ childprocess (0.2.3)
50
+ ffi (~> 1.0.6)
51
51
  cucumber (1.1.9)
52
52
  builder (>= 2.1.2)
53
53
  diff-lcs (>= 1.1.2)
@@ -57,7 +57,7 @@ GEM
57
57
  diff-lcs (1.1.3)
58
58
  erubis (2.6.6)
59
59
  abstract (>= 1.0.0)
60
- ffi (1.1.5)
60
+ ffi (1.0.11)
61
61
  gherkin (2.9.3)
62
62
  json (>= 1.4.6)
63
63
  i18n (0.5.0)
@@ -111,7 +111,7 @@ GEM
111
111
  sqlite3 (1.3.6)
112
112
  term-ansicolor (1.0.7)
113
113
  thor (0.14.6)
114
- treetop (1.4.10)
114
+ treetop (1.4.11)
115
115
  polyglot
116
116
  polyglot (>= 0.3.1)
117
117
  tzinfo (0.3.33)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/draper/Dropbox/Development/shoulda-matchers
3
3
  specs:
4
- shoulda-matchers (1.3.0)
4
+ shoulda-matchers (1.4.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -39,16 +39,16 @@ GEM
39
39
  bundler
40
40
  rake
41
41
  arel (2.2.3)
42
- aruba (0.4.11)
43
- childprocess (>= 0.2.3)
42
+ aruba (0.5.0)
43
+ childprocess (= 0.2.3)
44
44
  cucumber (>= 1.1.1)
45
45
  ffi (>= 1.0.11)
46
- rspec (>= 2.7.0)
46
+ rspec-expectations (>= 2.7.0)
47
47
  bourne (1.1.2)
48
48
  mocha (= 0.10.5)
49
49
  builder (3.0.3)
50
- childprocess (0.3.5)
51
- ffi (~> 1.0, >= 1.0.6)
50
+ childprocess (0.2.3)
51
+ ffi (~> 1.0.6)
52
52
  cucumber (1.1.9)
53
53
  builder (>= 2.1.2)
54
54
  diff-lcs (>= 1.1.2)
@@ -57,7 +57,7 @@ GEM
57
57
  term-ansicolor (>= 1.0.6)
58
58
  diff-lcs (1.1.3)
59
59
  erubis (2.7.0)
60
- ffi (1.1.5)
60
+ ffi (1.0.11)
61
61
  gherkin (2.9.3)
62
62
  json (>= 1.4.6)
63
63
  hike (1.2.1)
@@ -131,7 +131,7 @@ GEM
131
131
  term-ansicolor (1.0.7)
132
132
  thor (0.14.6)
133
133
  tilt (1.3.3)
134
- treetop (1.4.10)
134
+ treetop (1.4.11)
135
135
  polyglot
136
136
  polyglot (>= 0.3.1)
137
137
  tzinfo (0.3.33)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/draper/Dropbox/Development/shoulda-matchers
3
3
  specs:
4
- shoulda-matchers (1.3.0)
4
+ shoulda-matchers (1.4.0)
5
5
  activesupport (>= 3.0.0)
6
6
 
7
7
  GEM
@@ -38,16 +38,16 @@ GEM
38
38
  bundler
39
39
  rake
40
40
  arel (3.0.2)
41
- aruba (0.4.11)
42
- childprocess (>= 0.2.3)
41
+ aruba (0.5.0)
42
+ childprocess (= 0.2.3)
43
43
  cucumber (>= 1.1.1)
44
44
  ffi (>= 1.0.11)
45
- rspec (>= 2.7.0)
45
+ rspec-expectations (>= 2.7.0)
46
46
  bourne (1.1.2)
47
47
  mocha (= 0.10.5)
48
48
  builder (3.0.3)
49
- childprocess (0.3.5)
50
- ffi (~> 1.0, >= 1.0.6)
49
+ childprocess (0.2.3)
50
+ ffi (~> 1.0.6)
51
51
  cucumber (1.1.9)
52
52
  builder (>= 2.1.2)
53
53
  diff-lcs (>= 1.1.2)
@@ -56,7 +56,7 @@ GEM
56
56
  term-ansicolor (>= 1.0.6)
57
57
  diff-lcs (1.1.3)
58
58
  erubis (2.7.0)
59
- ffi (1.1.5)
59
+ ffi (1.0.11)
60
60
  gherkin (2.9.3)
61
61
  json (>= 1.4.6)
62
62
  hike (1.2.1)
@@ -128,7 +128,7 @@ GEM
128
128
  term-ansicolor (1.0.7)
129
129
  thor (0.16.0)
130
130
  tilt (1.3.3)
131
- treetop (1.4.10)
131
+ treetop (1.4.11)
132
132
  polyglot
133
133
  polyglot (>= 0.3.1)
134
134
  tzinfo (0.3.33)
@@ -57,11 +57,21 @@ module Shoulda # :nodoc:
57
57
  end
58
58
 
59
59
  def description
60
- "allow mass assignment of #{@attribute}"
60
+ [base_description, role_description].compact.join(" ")
61
61
  end
62
62
 
63
63
  private
64
64
 
65
+ def base_description
66
+ "allow mass assignment of #{@attribute}"
67
+ end
68
+
69
+ def role_description
70
+ if role != :default
71
+ "as #{role}"
72
+ end
73
+ end
74
+
65
75
  def role
66
76
  @options[:role] || :default
67
77
  end
@@ -154,7 +154,7 @@ module Shoulda # :nodoc:
154
154
  end
155
155
 
156
156
  def message_finder
157
- @message_finder ||= @message_finder_factory.new(@instance, @attribute)
157
+ @message_finder_factory.new(@instance, @attribute)
158
158
  end
159
159
  end
160
160
  end
@@ -22,6 +22,8 @@ module Shoulda # :nodoc:
22
22
  end
23
23
 
24
24
  class EnsureInclusionOfMatcher < ValidationMatcher # :nodoc:
25
+ ARBITRARY_OUTSIDE_STRING = "shouldamatchersteststring"
26
+
25
27
  def initialize(attribute)
26
28
  super(attribute)
27
29
  @options = {}
@@ -138,20 +140,14 @@ module Shoulda # :nodoc:
138
140
  end
139
141
 
140
142
  def disallows_value_outside_of_array?
141
- if value_outside_of_array
142
- disallows_value_of(value_outside_of_array)
143
- else
144
- raise CouldNotDetermineValueOutsideOfArray
145
- end
143
+ disallows_value_of(value_outside_of_array)
146
144
  end
147
145
 
148
146
  def value_outside_of_array
149
- found = @array.detect do |item|
150
- !@array.include?(item.next)
151
- end
152
-
153
- if found
154
- found.next
147
+ if @array.include?(ARBITRARY_OUTSIDE_STRING)
148
+ raise CouldNotDetermineValueOutsideOfArray
149
+ else
150
+ ARBITRARY_OUTSIDE_STRING
155
151
  end
156
152
  end
157
153
  end
@@ -1,5 +1,5 @@
1
1
  module Shoulda
2
2
  module Matchers
3
- VERSION = '1.4.0'.freeze
3
+ VERSION = '1.4.1'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,24 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher do
4
+ describe "#description" do
5
+ context 'without a role' do
6
+ it 'includes the attribute name' do
7
+ matcher = Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher.new(:attr)
8
+ matcher.description.should eq("allow mass assignment of attr")
9
+ end
10
+ end
11
+
12
+ if active_model_3_1?
13
+ context 'with a role' do
14
+ it 'includes the attribute name and the role' do
15
+ matcher = Shoulda::Matchers::ActiveModel::AllowMassAssignmentOfMatcher.new(:attr).as(:admin)
16
+ matcher.description.should eq("allow mass assignment of attr as admin")
17
+ end
18
+ end
19
+ end
20
+ end
21
+
4
22
  context "an attribute that is blacklisted from mass-assignment" do
5
23
  let(:model) do
6
24
  define_model(:example, :attr => :string) do
@@ -79,6 +79,14 @@ describe Shoulda::Matchers::ActiveModel::AllowValueMatcher do
79
79
  matcher = allow_value("foo").for(:baz)
80
80
  matcher.description.should eq('allow baz to be set to "foo"')
81
81
  end
82
+
83
+ it "allows you to call description before calling matches?" do
84
+ model = define_model(:example, :attr => :string).new
85
+ matcher = Shoulda::Matchers::ActiveModel::AllowValueMatcher.new("foo").for(:attr)
86
+ matcher.description
87
+
88
+ expect { matcher.matches?(model) }.not_to raise_error
89
+ end
82
90
  end
83
91
 
84
92
  context "an AllowValueMatcher with no values" do
@@ -12,11 +12,20 @@ describe Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher do
12
12
  end
13
13
  end
14
14
 
15
+ context "with true/false values" do
16
+ it "can verify outside values to ensure the negative case" do
17
+ model = define_model(:example, :attr => :string).new
18
+
19
+ model.should_not ensure_inclusion_of(:attr).in_array([true, false])
20
+ end
21
+ end
22
+
15
23
  context "where we cannot determine a value outside the array" do
16
24
  it "should raise a custom exception" do
17
- @model = define_model(:example, :attr => :string).new
25
+ model = define_model(:example, :attr => :string).new
18
26
 
19
- expect { @model.should ensure_inclusion_of(:attr).in_array([""]) }.to raise_error Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
27
+ arbitrary_string = Shoulda::Matchers::ActiveModel::EnsureInclusionOfMatcher::ARBITRARY_OUTSIDE_STRING
28
+ expect { model.should ensure_inclusion_of(:attr).in_array([arbitrary_string]) }.to raise_error Shoulda::Matchers::ActiveModel::CouldNotDetermineValueOutsideOfArray
20
29
  end
21
30
  end
22
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoulda-matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2012-10-05 00:00:00.000000000 Z
17
+ date: 2012-10-15 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport
@@ -289,7 +289,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
289
  version: '0'
290
290
  segments:
291
291
  - 0
292
- hash: 813377459972856034
292
+ hash: 2974632708122422691
293
293
  required_rubygems_version: !ruby/object:Gem::Requirement
294
294
  none: false
295
295
  requirements:
@@ -298,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  segments:
300
300
  - 0
301
- hash: 813377459972856034
301
+ hash: 2974632708122422691
302
302
  requirements: []
303
303
  rubyforge_project:
304
304
  rubygems_version: 1.8.24