remockable 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +83 -0
- data/Gemfile +1 -1
- data/README.markdown +6 -5
- data/lib/remockable/active_model.rb +0 -2
- data/lib/remockable/active_record/belong_to.rb +2 -4
- data/lib/remockable/active_record/have_and_belong_to_many.rb +1 -3
- data/lib/remockable/active_record/have_default_scope.rb +2 -2
- data/lib/remockable/active_record/have_many.rb +2 -2
- data/lib/remockable/active_record/have_one.rb +2 -2
- data/lib/remockable/active_record/have_scope.rb +1 -1
- data/lib/remockable/version.rb +1 -1
- data/remockable.gemspec +4 -3
- data/spec/active_model/allow_values_for_spec.rb +1 -1
- data/spec/active_record/belong_to_spec.rb +1 -6
- data/spec/active_record/have_and_belong_to_many_spec.rb +1 -17
- data/spec/active_record/have_default_scope_spec.rb +23 -23
- data/spec/active_record/have_many_spec.rb +1 -14
- data/spec/active_record/have_one_spec.rb +2 -7
- data/spec/active_record/have_scope_spec.rb +31 -31
- data/spec/support/active_record_example_group.rb +2 -5
- data/spec/support/shared/an_active_record_matcher.rb +2 -2
- metadata +52 -32
- data/lib/remockable/active_model/allow_mass_assignment_of.rb +0 -33
- data/spec/active_model/allow_mass_assignment_of_spec.rb +0 -86
data/CHANGELOG.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.2.0 (2013-10-18)
|
4
|
+
|
5
|
+
* Remove support Rails 3 ([Tyler Hunt][tylerhunt])
|
6
|
+
* Support Rails 4 ([Tyler Hunt][tylerhunt])
|
7
|
+
|
8
|
+
## 0.1.2 (2013-06-17)
|
9
|
+
|
10
|
+
* Specify license in gemspec ([Tyler Hunt][tylerhunt])
|
11
|
+
* Add missing dependency require statements ([Tyler Hunt][tylerhunt])
|
12
|
+
* Restore support for Ruby 1.8 ([Tyler Hunt][tylerhunt])
|
13
|
+
|
14
|
+
## 0.1.1 (2012-04-25)
|
15
|
+
|
16
|
+
* Do not rely on a `:with` option having `#to_a` ([Tyler Hunt][tylerhunt])
|
17
|
+
* Update `:if`/`:unless` support to use instance ([Tyler Hunt][tylerhunt])
|
18
|
+
|
19
|
+
## 0.1.0 (2012-02-26)
|
20
|
+
|
21
|
+
* Support `:if` and `:unless` options ([Tyler Hunt][tylerhunt])
|
22
|
+
* Remove support for multiple attributes ([Tyler Hunt][tylerhunt])
|
23
|
+
|
24
|
+
## 0.0.12 (2012-01-18)
|
25
|
+
|
26
|
+
* Use the subject instead of making a new instance ([Tyler Hunt][tylerhunt])
|
27
|
+
* Make rspec-mocks a runtime dependency ([Tyler Hunt][tylerhunt])
|
28
|
+
|
29
|
+
## 0.0.11 (2012-01-18)
|
30
|
+
|
31
|
+
* Support role-based mass-assignment security ([Tyler Hunt][tylerhunt])
|
32
|
+
* Fix issue with instance variables in matchers ([Tyler Hunt][tylerhunt])
|
33
|
+
|
34
|
+
## 0.0.10 (2011-10-29)
|
35
|
+
|
36
|
+
* Add `accept_nested_attributes_for` matcher ([Tyler Hunt][tylerhunt])
|
37
|
+
* Add `allow_values_for` matcher ([Tyler Hunt][tylerhunt])
|
38
|
+
* Remove unsupported default scope query methods ([Tyler Hunt][tylerhunt])
|
39
|
+
* Update mass-assignment matcher for Rails 3.1 ([Tyler Hunt][tylerhunt])
|
40
|
+
|
41
|
+
## 0.0.9 (2011-07-12)
|
42
|
+
|
43
|
+
* Ensure that the association types are matched ([Tyler Hunt][tylerhunt])
|
44
|
+
* Fix an issue in the matching logic ([Tyler Hunt][tylerhunt])
|
45
|
+
|
46
|
+
## 0.0.8 (2011-07-06)
|
47
|
+
|
48
|
+
* Support Rails 3.1 ([Jacob Swanner][jswanner])
|
49
|
+
|
50
|
+
## 0.0.7 (2011-07-05)
|
51
|
+
|
52
|
+
* Add `have_default_scope` matcher ([Tyler Hunt][tylerhunt])
|
53
|
+
|
54
|
+
## 0.0.6 (2011-05-09)
|
55
|
+
|
56
|
+
* Add Active Record validation matchers ([Tyler Hunt][tylerhunt])
|
57
|
+
|
58
|
+
## 0.0.5 (2011-05-07)
|
59
|
+
|
60
|
+
* Add association matchers ([Tyler Hunt][tylerhunt])
|
61
|
+
|
62
|
+
## 0.0.4 (2011-05-07)
|
63
|
+
|
64
|
+
* Add `allow_mass_assignment_of` matcher ([Tyler Hunt][tylerhunt])
|
65
|
+
* Add missing dependency require statement ([Tyler Hunt][tylerhunt])
|
66
|
+
* Fix a bug in the matcher logic ([Tyler Hunt][tylerhunt])
|
67
|
+
|
68
|
+
## 0.0.3 (2011-03-11)
|
69
|
+
|
70
|
+
* Update matchers to assume subject is an instance ([Tyler Hunt][tylerhunt])
|
71
|
+
|
72
|
+
## 0.0.2 (2011-03-11)
|
73
|
+
|
74
|
+
* Add additional matchers ([Tyler Hunt][tylerhunt])
|
75
|
+
* Require RSpec 2.5 ([Tyler Hunt][tylerhunt])
|
76
|
+
* Support multiple attributes ([Tyler Hunt][tylerhunt])
|
77
|
+
|
78
|
+
## 0.0.1 (2011-02-21)
|
79
|
+
|
80
|
+
* Initial release ([Tyler Hunt][tylerhunt])
|
81
|
+
|
82
|
+
[jswanner]: https://github.com/jswanner
|
83
|
+
[tylerhunt]: https://github.com/tylerhunt
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -7,13 +7,15 @@
|
|
7
7
|
|
8
8
|
A collection of RSpec 2 matchers to simplify your web app specs.
|
9
9
|
|
10
|
+
*Note:* Rails 3 support was dropped in version 0.2.
|
11
|
+
|
10
12
|
|
11
13
|
## Background
|
12
14
|
|
13
15
|
The goal of this project is to provide a modern replacement to the now
|
14
16
|
unmaintained Remarkable project. Remarkable was a great asset when Rails 2.3
|
15
|
-
was current, but
|
16
|
-
|
17
|
+
was current, but a gap has been left by the unreleased Remarkable 4.0 since the
|
18
|
+
release of Rails 3 and 4.
|
17
19
|
|
18
20
|
In looking at the code for Remarkable to determine the feasibility of continuing
|
19
21
|
work on Remarkable itself, it seems clear that the scope of that project has
|
@@ -24,7 +26,7 @@ the original goal of Remarkable in spirit.
|
|
24
26
|
|
25
27
|
## Installation
|
26
28
|
|
27
|
-
Add this line to your application's Gemfile
|
29
|
+
Add this line to your application's `Gemfile`:
|
28
30
|
|
29
31
|
``` ruby
|
30
32
|
gem 'remockable'
|
@@ -48,7 +50,6 @@ classes.
|
|
48
50
|
|
49
51
|
The following Active Model matchers are supported:
|
50
52
|
|
51
|
-
* `allow_mass_assignment_of`
|
52
53
|
* `validate_acceptance_of`
|
53
54
|
* `validate_confirmation_of`
|
54
55
|
* `validate_exclusion_of`
|
@@ -85,4 +86,4 @@ The following Active Record matchers are supported:
|
|
85
86
|
|
86
87
|
## Copyright
|
87
88
|
|
88
|
-
Copyright © 2010-
|
89
|
+
Copyright © 2010-2013 Tyler Hunt. See LICENSE for details.
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'remockable/active_model/helpers'
|
2
2
|
|
3
|
-
require 'remockable/active_model/allow_mass_assignment_of'
|
4
|
-
|
5
3
|
require 'remockable/active_model/allow_values_for'
|
6
4
|
require 'remockable/active_model/validate_acceptance_of'
|
7
5
|
require 'remockable/active_model/validate_confirmation_of'
|
@@ -4,10 +4,8 @@ RSpec::Matchers.define(:belong_to) do |*association|
|
|
4
4
|
@expected = association.extract_options!
|
5
5
|
@association = association.shift
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
dependent counter_cache include polymorphic readonly validate autosave touch
|
10
|
-
inverse_of)
|
7
|
+
valid_options %w(class_name foreign_key foreign_type primary_key dependent
|
8
|
+
counter_cache polymorphic validate autosave touch inverse_of)
|
11
9
|
|
12
10
|
match do |actual|
|
13
11
|
if association = subject.class.reflect_on_association(@association)
|
@@ -4,10 +4,8 @@ RSpec::Matchers.define(:have_and_belong_to_many) do |*association|
|
|
4
4
|
@expected = association.extract_options!
|
5
5
|
@association = association.shift
|
6
6
|
|
7
|
-
unsupported_options %w(extend)
|
8
7
|
valid_options %w(class_name join_table foreign_key association_foreign_key
|
9
|
-
|
10
|
-
group having limit offset select readonly validate autosave)
|
8
|
+
validate autosave)
|
11
9
|
|
12
10
|
match do |actual|
|
13
11
|
if association = subject.class.reflect_on_association(@association)
|
@@ -7,8 +7,8 @@ RSpec::Matchers.define(:have_default_scope) do |*expected|
|
|
7
7
|
valid_options %w()
|
8
8
|
|
9
9
|
match do |actual|
|
10
|
-
if subject.class.respond_to?(:
|
11
|
-
scope = subject.class.
|
10
|
+
if subject.class.respond_to?(:all)
|
11
|
+
scope = subject.class.all
|
12
12
|
|
13
13
|
if scope.is_a?(ActiveRecord::Relation)
|
14
14
|
if @relation
|
@@ -4,8 +4,8 @@ RSpec::Matchers.define(:have_many) do |*association|
|
|
4
4
|
@expected = association.extract_options!
|
5
5
|
@association = association.shift
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
valid_options %w(class_name foreign_key primary_key dependent counter_cache
|
8
|
+
as through source source_type validate autosave inverse_of)
|
9
9
|
|
10
10
|
match do |actual|
|
11
11
|
if association = subject.class.reflect_on_association(@association)
|
@@ -4,8 +4,8 @@ RSpec::Matchers.define(:have_one) do |*association|
|
|
4
4
|
@expected = association.extract_options!
|
5
5
|
@association = association.shift
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
valid_options %w(class_name dependent foreign_key primary_key as through
|
8
|
+
source source_type validate autosave inverse_of)
|
9
9
|
|
10
10
|
match do |actual|
|
11
11
|
if association = subject.class.reflect_on_association(@association)
|
@@ -38,7 +38,7 @@ RSpec::Matchers.define(:have_scope) do |*name|
|
|
38
38
|
query_methods = %w(eager_load from group having includes joins limit lock offset order preload readonly reorder select where)
|
39
39
|
|
40
40
|
if query_methods.include?(method.to_s)
|
41
|
-
@relation ||= subject.class.
|
41
|
+
@relation ||= subject.class.all
|
42
42
|
@relation = @relation.send(method, *args)
|
43
43
|
self
|
44
44
|
else
|
data/lib/remockable/version.rb
CHANGED
data/remockable.gemspec
CHANGED
@@ -8,12 +8,13 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.homepage = 'http://github.com/tylerhunt/remockable'
|
9
9
|
spec.license = 'MIT'
|
10
10
|
|
11
|
-
spec.add_dependency 'activemodel', '
|
12
|
-
spec.add_dependency 'activerecord', '
|
13
|
-
spec.add_dependency 'activesupport', '
|
11
|
+
spec.add_dependency 'activemodel', '>= 3.0'
|
12
|
+
spec.add_dependency 'activerecord', '>= 3.0'
|
13
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
14
14
|
spec.add_dependency 'rspec-core', '~> 2.0'
|
15
15
|
spec.add_dependency 'rspec-expectations', '~> 2.0'
|
16
16
|
spec.add_dependency 'rspec-mocks', '~> 2.0'
|
17
|
+
spec.add_development_dependency 'rake'
|
17
18
|
spec.add_development_dependency 'sqlite3', '~> 1.3.4'
|
18
19
|
|
19
20
|
spec.files = `git ls-files`.split($/)
|
@@ -43,20 +43,15 @@ describe :belong_to do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
with_option(:class_name, 'Company', 'Organization')
|
46
|
-
with_option(:conditions, { :id => 1 }, { :id => 2 })
|
47
|
-
with_option(:select, %w(id), %w(name))
|
48
46
|
with_option(:foreign_key, :company_id, :organization_id)
|
47
|
+
with_option(:foreign_type, :company_type, :organization_type)
|
49
48
|
with_option(:primary_key, :id, :company_id)
|
50
49
|
with_option(:dependent, :destroy, :nullify)
|
51
50
|
with_option(:counter_cache, true, false)
|
52
|
-
with_option(:include, :users, :employees)
|
53
51
|
with_option(:polymorphic, true, false)
|
54
|
-
with_option(:readonly, true, false)
|
55
52
|
with_option(:validate, true, false)
|
56
53
|
with_option(:autosave, true, false)
|
57
54
|
with_option(:touch, true, false)
|
58
55
|
with_option(:inverse_of, :users, :employees)
|
59
|
-
|
60
|
-
with_unsupported_option(:extend, Module.new)
|
61
56
|
end
|
62
57
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe :have_and_belong_to_many do
|
4
4
|
let(:macro) { :has_and_belongs_to_many }
|
5
|
-
let(:options) { [:tags, { :
|
5
|
+
let(:options) { [:tags, { :validate => true }] }
|
6
6
|
|
7
7
|
it_behaves_like 'an Active Record matcher' do
|
8
8
|
let(:model) { build_class(:User, ActiveRecord::Base) }
|
@@ -45,23 +45,7 @@ describe :have_and_belong_to_many do
|
|
45
45
|
with_option(:join_table, 'tags_users', 'user_tags')
|
46
46
|
with_option(:foreign_key, :user_id, :tagged_id)
|
47
47
|
with_option(:association_foreign_key, :tag_id, :role_id)
|
48
|
-
with_option(:conditions, { :active => true }, { :active => false })
|
49
|
-
with_option(:order, :name, :created_at)
|
50
|
-
with_option(:uniq, true, false)
|
51
|
-
with_option(:finder_sql, 'SELECT * FROM user_tags', 'SELECT * FROM tags_users')
|
52
|
-
with_option(:counter_sql, 'SELECT COUNT(*) FROM user_tags', 'SELECT COUNT(*) FROM tags_users')
|
53
|
-
with_option(:delete_sql, 'DELETE FROM user_tags', 'DELETE FROM tags_users')
|
54
|
-
with_option(:insert_sql, 'INSERT INTO user_tags', 'INSERT INTO tags_users')
|
55
|
-
with_option(:include, :statistics, :changes)
|
56
|
-
with_option(:group, 'usage_count', 'changes_count')
|
57
|
-
with_option(:having, 'usage_count > 5', 'changes_count > 5')
|
58
|
-
with_option(:limit, 5, 10)
|
59
|
-
with_option(:offset, 10, 20)
|
60
|
-
with_option(:select, %w(id), %w(name))
|
61
|
-
with_option(:readonly, true, false)
|
62
48
|
with_option(:validate, true, false)
|
63
49
|
with_option(:autosave, true, false)
|
64
|
-
|
65
|
-
with_unsupported_option(:extend, Module.new)
|
66
50
|
end
|
67
51
|
end
|
@@ -25,7 +25,7 @@ describe :have_default_scope do
|
|
25
25
|
|
26
26
|
context 'without arguments' do
|
27
27
|
it 'matches if a default scope exists' do
|
28
|
-
model.instance_eval { default_scope(order(:id)) }
|
28
|
+
model.instance_eval { default_scope(-> { order(:id) }) }
|
29
29
|
model.should have_default_scope
|
30
30
|
end
|
31
31
|
|
@@ -36,132 +36,132 @@ describe :have_default_scope do
|
|
36
36
|
|
37
37
|
context 'with a from value' do
|
38
38
|
it 'matches if the scope exists and the query matches' do
|
39
|
-
model.instance_eval { default_scope(from('users')) }
|
39
|
+
model.instance_eval { default_scope(-> { from('users') }) }
|
40
40
|
model.should have_default_scope.from('users')
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not match if the query does not match' do
|
44
|
-
model.instance_eval { default_scope(from('users')) }
|
44
|
+
model.instance_eval { default_scope(-> { from('users') }) }
|
45
45
|
model.should_not have_default_scope.from('friends')
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'with a group value' do
|
50
50
|
it 'matches if the scope exists and the query matches' do
|
51
|
-
model.instance_eval { default_scope(group('one')) }
|
51
|
+
model.instance_eval { default_scope(-> { group('one') }) }
|
52
52
|
model.should have_default_scope.group('one')
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'does not match if the query does not match' do
|
56
|
-
model.instance_eval { default_scope(group('one')) }
|
56
|
+
model.instance_eval { default_scope(-> { group('one') }) }
|
57
57
|
model.should_not have_default_scope.group('two')
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with a having value' do
|
62
62
|
it 'matches if the scope exists and the query matches' do
|
63
|
-
model.instance_eval { default_scope(having('COUNT(*) > 1')) }
|
63
|
+
model.instance_eval { default_scope(-> { having('COUNT(*) > 1') }) }
|
64
64
|
model.should have_default_scope.having('COUNT(*) > 1')
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'does not match if the query does not match' do
|
68
|
-
model.instance_eval { default_scope(having('COUNT(*) > 1')) }
|
68
|
+
model.instance_eval { default_scope(-> { having('COUNT(*) > 1') }) }
|
69
69
|
model.should_not have_default_scope.having('COUNT(*) > 2')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'with a having value' do
|
74
74
|
it 'matches if the scope exists and the query matches' do
|
75
|
-
model.instance_eval { default_scope(having('COUNT(*) > 1')) }
|
75
|
+
model.instance_eval { default_scope(-> { having('COUNT(*) > 1') }) }
|
76
76
|
model.should have_default_scope.having('COUNT(*) > 1')
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'does not match if the query does not match' do
|
80
|
-
model.instance_eval { default_scope(having('COUNT(*) > 1')) }
|
80
|
+
model.instance_eval { default_scope(-> { having('COUNT(*) > 1') }) }
|
81
81
|
model.should_not have_default_scope.having('COUNT(*) > 2')
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with a joins value' do
|
86
86
|
it 'matches if the scope exists and the query matches' do
|
87
|
-
model.instance_eval { default_scope(joins('INNER JOIN friends')) }
|
87
|
+
model.instance_eval { default_scope(-> { joins('INNER JOIN friends') }) }
|
88
88
|
model.should have_default_scope.joins('INNER JOIN friends')
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'does not match if the query does not match' do
|
92
|
-
model.instance_eval { default_scope(joins('INNER JOIN friends')) }
|
92
|
+
model.instance_eval { default_scope(-> { joins('INNER JOIN friends') }) }
|
93
93
|
model.should_not have_default_scope.joins('INNER JOIN enemies')
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'with a limit value' do
|
98
98
|
it 'matches if the scope exists and the query matches' do
|
99
|
-
model.instance_eval { default_scope(limit(10)) }
|
99
|
+
model.instance_eval { default_scope(-> { limit(10) }) }
|
100
100
|
model.should have_default_scope.limit(10)
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'does not match if the query does not match' do
|
104
|
-
model.instance_eval { default_scope(limit(10)) }
|
104
|
+
model.instance_eval { default_scope(-> { limit(10) }) }
|
105
105
|
model.should_not have_default_scope.limit(15)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
context 'with an offset value' do
|
110
110
|
it 'matches if the scope exists and the query matches' do
|
111
|
-
model.instance_eval { default_scope(offset(10)) }
|
111
|
+
model.instance_eval { default_scope(-> { offset(10) }) }
|
112
112
|
model.should have_default_scope.offset(10)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'does not match if the query does not match' do
|
116
|
-
model.instance_eval { default_scope(offset(10)) }
|
116
|
+
model.instance_eval { default_scope(-> { offset(10) }) }
|
117
117
|
model.should_not have_default_scope.offset(15)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
context 'with an order value' do
|
122
122
|
it 'matches if the scope exists and the query matches' do
|
123
|
-
model.instance_eval { default_scope(order('one')) }
|
123
|
+
model.instance_eval { default_scope(-> { order('one') }) }
|
124
124
|
model.should have_default_scope.order('one')
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'does not match if the query does not match' do
|
128
|
-
model.instance_eval { default_scope(order('one')) }
|
128
|
+
model.instance_eval { default_scope(-> { order('one') }) }
|
129
129
|
model.should_not have_default_scope.order('id')
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
context 'with a reorder value' do
|
134
134
|
it 'matches if the scope exists and the query matches' do
|
135
|
-
model.instance_eval { default_scope(reorder('one')) }
|
135
|
+
model.instance_eval { default_scope(-> { reorder('one') }) }
|
136
136
|
model.should have_default_scope.reorder('one')
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'does not match if the query does not match' do
|
140
|
-
model.instance_eval { default_scope(reorder('one')) }
|
140
|
+
model.instance_eval { default_scope(-> { reorder('one') }) }
|
141
141
|
model.should_not have_default_scope.reorder('id')
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
context 'with a select value' do
|
146
146
|
it 'matches if the scope exists and the query matches' do
|
147
|
-
model.instance_eval { default_scope(select('one')) }
|
147
|
+
model.instance_eval { default_scope(-> { select('one') }) }
|
148
148
|
model.should have_default_scope.select('one')
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'does not match if the query does not match' do
|
152
|
-
model.instance_eval { default_scope(select('one')) }
|
152
|
+
model.instance_eval { default_scope(-> { select('one') }) }
|
153
153
|
model.should_not have_default_scope.select('id')
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
context 'with a where value' do
|
158
158
|
it 'matches if the scope exists and the query matches' do
|
159
|
-
model.instance_eval { default_scope(where(:one => nil)) }
|
159
|
+
model.instance_eval { default_scope(-> { where(:one => nil) }) }
|
160
160
|
model.should have_default_scope.where(:one => nil)
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'does not match if the query does not match' do
|
164
|
-
model.instance_eval { default_scope(where(:one => nil)) }
|
164
|
+
model.instance_eval { default_scope(-> { where(:one => nil) }) }
|
165
165
|
model.should_not have_default_scope.where(:one => 1)
|
166
166
|
end
|
167
167
|
end
|
@@ -42,29 +42,16 @@ describe :have_many do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
with_option(:class_name, 'Post', 'Blog')
|
45
|
-
with_option(:conditions, { :published => true }, { :published => false })
|
46
|
-
with_option(:order, %w(published_at), %w(title))
|
47
45
|
with_option(:foreign_key, :post_id, :blog_id)
|
48
46
|
with_option(:primary_key, :id, :post_id)
|
49
47
|
with_option(:dependent, :destroy, :nullify)
|
50
|
-
with_option(:
|
51
|
-
with_option(:counter_sql, 'SELECT COUNT(*) FROM posts', 'SELECT COUNT(*) FROM blogs')
|
52
|
-
with_option(:include, :comments, :trackbacks)
|
53
|
-
with_option(:group, 'comments_count', 'trackbacks_count')
|
54
|
-
with_option(:having, 'comments_count > 5', 'trackbacks_count > 5')
|
55
|
-
with_option(:limit, 5, 10)
|
56
|
-
with_option(:offset, 10, 20)
|
57
|
-
with_option(:select, %w(id), %w(title))
|
48
|
+
with_option(:counter_cache, :post_count, :posts_count)
|
58
49
|
with_option(:as, :postable, :bloggable)
|
59
50
|
with_option(:through, :postings, :bloggings)
|
60
51
|
with_option(:source, :piece, :work)
|
61
52
|
with_option(:source_type, 'Post', 'Blog')
|
62
|
-
with_option(:uniq, true, false)
|
63
|
-
with_option(:readonly, true, false)
|
64
53
|
with_option(:validate, true, false)
|
65
54
|
with_option(:autosave, true, false)
|
66
55
|
with_option(:inverse_of, :users, :employees)
|
67
|
-
|
68
|
-
with_unsupported_option(:extend, Module.new)
|
69
56
|
end
|
70
57
|
end
|
@@ -42,20 +42,15 @@ describe :have_one do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
with_option(:class_name, 'Address', 'Location')
|
45
|
-
with_option(:conditions, { :id => 1 }, { :id => 2 })
|
46
|
-
with_option(:order, %w(id), %w(name))
|
47
45
|
with_option(:dependent, :destroy, :nullify)
|
48
46
|
with_option(:foreign_key, :address_id, :location_id)
|
49
47
|
with_option(:primary_key, :id, :address_id)
|
50
|
-
with_option(:include, :country, :state)
|
51
48
|
with_option(:as, :addressable, :locatable)
|
52
|
-
with_option(:select, %w(id), %w(name))
|
53
49
|
with_option(:through, :offices, :locations)
|
54
|
-
with_option(:
|
50
|
+
with_option(:source, :addressable, :contactable, through: :offices)
|
51
|
+
with_option(:source_type, 'Company', 'Organization', through: :offices)
|
55
52
|
with_option(:validate, true, false)
|
56
53
|
with_option(:autosave, true, false)
|
57
54
|
with_option(:inverse_of, :user, :employee)
|
58
|
-
|
59
|
-
with_unsupported_option(:extend, Module.new)
|
60
55
|
end
|
61
56
|
end
|
@@ -25,7 +25,7 @@ describe :have_scope do
|
|
25
25
|
|
26
26
|
context 'with a scope name' do
|
27
27
|
it 'matches if the scope exists' do
|
28
|
-
model.instance_eval { scope(:no_one, where(:one => nil)) }
|
28
|
+
model.instance_eval { scope(:no_one, -> { where(:one => nil) }) }
|
29
29
|
model.should have_scope(:no_one)
|
30
30
|
end
|
31
31
|
|
@@ -36,180 +36,180 @@ describe :have_scope do
|
|
36
36
|
|
37
37
|
context 'with an eager_load value' do
|
38
38
|
it 'matches if the scope exists and the query matches' do
|
39
|
-
model.instance_eval { scope(:loaded, eager_load(:order)) }
|
39
|
+
model.instance_eval { scope(:loaded, -> { eager_load(:order) }) }
|
40
40
|
model.should have_scope(:loaded).eager_load(:order)
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not match if the query does not match' do
|
44
|
-
model.instance_eval { scope(:loaded, eager_load(:order)) }
|
44
|
+
model.instance_eval { scope(:loaded, -> { eager_load(:order) }) }
|
45
45
|
model.should_not have_scope(:loaded).eager_load(:from)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'with a from value' do
|
50
50
|
it 'matches if the scope exists and the query matches' do
|
51
|
-
model.instance_eval { scope(:used, from('users')) }
|
51
|
+
model.instance_eval { scope(:used, -> { from('users') }) }
|
52
52
|
model.should have_scope(:used).from('users')
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'does not match if the query does not match' do
|
56
|
-
model.instance_eval { scope(:used, from('users')) }
|
56
|
+
model.instance_eval { scope(:used, -> { from('users') }) }
|
57
57
|
model.should_not have_scope(:used).from('friends')
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with a group value' do
|
62
62
|
it 'matches if the scope exists and the query matches' do
|
63
|
-
model.instance_eval { scope(:grouped, group('one')) }
|
63
|
+
model.instance_eval { scope(:grouped, -> { group('one') }) }
|
64
64
|
model.should have_scope(:grouped).group('one')
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'does not match if the query does not match' do
|
68
|
-
model.instance_eval { scope(:grouped, group('one')) }
|
68
|
+
model.instance_eval { scope(:grouped, -> { group('one') }) }
|
69
69
|
model.should_not have_scope(:grouped).group('two')
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'with a having value' do
|
74
74
|
it 'matches if the scope exists and the query matches' do
|
75
|
-
model.instance_eval { scope(:had, having('COUNT(*) > 1')) }
|
75
|
+
model.instance_eval { scope(:had, -> { having('COUNT(*) > 1') }) }
|
76
76
|
model.should have_scope(:had).having('COUNT(*) > 1')
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'does not match if the query does not match' do
|
80
|
-
model.instance_eval { scope(:had, having('COUNT(*) > 1')) }
|
80
|
+
model.instance_eval { scope(:had, -> { having('COUNT(*) > 1') }) }
|
81
81
|
model.should_not have_scope(:had).having('COUNT(*) > 2')
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
context 'with an includes value' do
|
86
86
|
it 'matches if the scope exists and the query matches' do
|
87
|
-
model.instance_eval { scope(:joined, includes(:company)) }
|
87
|
+
model.instance_eval { scope(:joined, -> { includes(:company) }) }
|
88
88
|
model.should have_scope(:joined).includes(:company)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'does not match if the query does not match' do
|
92
|
-
model.instance_eval { scope(:joined, includes(:company)) }
|
92
|
+
model.instance_eval { scope(:joined, -> { includes(:company) }) }
|
93
93
|
model.should_not have_scope(:joined).includes(:address)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
context 'with a joins value' do
|
98
98
|
it 'matches if the scope exists and the query matches' do
|
99
|
-
model.instance_eval { scope(:joined, joins('INNER JOIN friends')) }
|
99
|
+
model.instance_eval { scope(:joined, -> { joins('INNER JOIN friends') }) }
|
100
100
|
model.should have_scope(:joined).joins('INNER JOIN friends')
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'does not match if the query does not match' do
|
104
|
-
model.instance_eval { scope(:joined, joins('INNER JOIN friends')) }
|
104
|
+
model.instance_eval { scope(:joined, -> { joins('INNER JOIN friends') }) }
|
105
105
|
model.should_not have_scope(:joined).joins('INNER JOIN enemies')
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
109
|
context 'with a limit value' do
|
110
110
|
it 'matches if the scope exists and the query matches' do
|
111
|
-
model.instance_eval { scope(:limited, limit(10)) }
|
111
|
+
model.instance_eval { scope(:limited, -> { limit(10) }) }
|
112
112
|
model.should have_scope(:limited).limit(10)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'does not match if the query does not match' do
|
116
|
-
model.instance_eval { scope(:limited, limit(10)) }
|
116
|
+
model.instance_eval { scope(:limited, -> { limit(10) }) }
|
117
117
|
model.should_not have_scope(:limited).limit(15)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
121
|
context 'with a lock value' do
|
122
122
|
it 'matches if the scope exists and the query matches' do
|
123
|
-
model.instance_eval { scope(:locked, lock(true)) }
|
123
|
+
model.instance_eval { scope(:locked, -> { lock(true) }) }
|
124
124
|
model.should have_scope(:locked).lock(true)
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'does not match if the query does not match' do
|
128
|
-
model.instance_eval { scope(:locked, lock(true)) }
|
128
|
+
model.instance_eval { scope(:locked, -> { lock(true) }) }
|
129
129
|
model.should_not have_scope(:locked).lock(false)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
133
|
context 'with an offset value' do
|
134
134
|
it 'matches if the scope exists and the query matches' do
|
135
|
-
model.instance_eval { scope(:shifted, offset(10)) }
|
135
|
+
model.instance_eval { scope(:shifted, -> { offset(10) }) }
|
136
136
|
model.should have_scope(:shifted).offset(10)
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'does not match if the query does not match' do
|
140
|
-
model.instance_eval { scope(:shifted, offset(10)) }
|
140
|
+
model.instance_eval { scope(:shifted, -> { offset(10) }) }
|
141
141
|
model.should_not have_scope(:shifted).offset(15)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
145
|
context 'with an order value' do
|
146
146
|
it 'matches if the scope exists and the query matches' do
|
147
|
-
model.instance_eval { scope(:ordered, order('one')) }
|
147
|
+
model.instance_eval { scope(:ordered, -> { order('one') }) }
|
148
148
|
model.should have_scope(:ordered).order('one')
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'does not match if the query does not match' do
|
152
|
-
model.instance_eval { scope(:ordered, order('one')) }
|
152
|
+
model.instance_eval { scope(:ordered, -> { order('one') }) }
|
153
153
|
model.should_not have_scope(:ordered).order('id')
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
157
|
context 'with a preload value' do
|
158
158
|
it 'matches if the scope exists and the query matches' do
|
159
|
-
model.instance_eval { scope(:preloaded, preload(:company)) }
|
159
|
+
model.instance_eval { scope(:preloaded, -> { preload(:company) }) }
|
160
160
|
model.should have_scope(:preloaded).preload(:company)
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'does not match if the query does not match' do
|
164
|
-
model.instance_eval { scope(:preloaded, preload(:company)) }
|
164
|
+
model.instance_eval { scope(:preloaded, -> { preload(:company) }) }
|
165
165
|
model.should_not have_scope(:preloaded).preload(:address)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
context 'with a readonly value' do
|
170
170
|
it 'matches if the scope exists and the query matches' do
|
171
|
-
model.instance_eval { scope(:prepared, readonly(false)) }
|
171
|
+
model.instance_eval { scope(:prepared, -> { readonly(false) }) }
|
172
172
|
model.should have_scope(:prepared).readonly(false)
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'does not match if the query does not match' do
|
176
|
-
model.instance_eval { scope(:prepared, readonly(false)) }
|
176
|
+
model.instance_eval { scope(:prepared, -> { readonly(false) }) }
|
177
177
|
model.should_not have_scope(:prepared).readonly(true)
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
181
|
context 'with a reorder value' do
|
182
182
|
it 'matches if the scope exists and the query matches' do
|
183
|
-
model.instance_eval { scope(:reordered, reorder('one')) }
|
183
|
+
model.instance_eval { scope(:reordered, -> { reorder('one') }) }
|
184
184
|
model.should have_scope(:reordered).reorder('one')
|
185
185
|
end
|
186
186
|
|
187
187
|
it 'does not match if the query does not match' do
|
188
|
-
model.instance_eval { scope(:reordered, reorder('one')) }
|
188
|
+
model.instance_eval { scope(:reordered, -> { reorder('one') }) }
|
189
189
|
model.should_not have_scope(:reordered).reorder('id')
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
193
193
|
context 'with a select value' do
|
194
194
|
it 'matches if the scope exists and the query matches' do
|
195
|
-
model.instance_eval { scope(:ones, select('one')) }
|
195
|
+
model.instance_eval { scope(:ones, -> { select('one') }) }
|
196
196
|
model.should have_scope(:ones).select('one')
|
197
197
|
end
|
198
198
|
|
199
199
|
it 'does not match if the query does not match' do
|
200
|
-
model.instance_eval { scope(:ones, select('one')) }
|
200
|
+
model.instance_eval { scope(:ones, -> { select('one') }) }
|
201
201
|
model.should_not have_scope(:ones).select('id')
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
205
|
context 'with a where value' do
|
206
206
|
it 'matches if the scope exists and the query matches' do
|
207
|
-
model.instance_eval { scope(:no_one, where(:one => nil)) }
|
207
|
+
model.instance_eval { scope(:no_one, -> { where(:one => nil) }) }
|
208
208
|
model.should have_scope(:no_one).where(:one => nil)
|
209
209
|
end
|
210
210
|
|
211
211
|
it 'does not match if the query does not match' do
|
212
|
-
model.instance_eval { scope(:no_one, where(:one => nil)) }
|
212
|
+
model.instance_eval { scope(:no_one, -> { where(:one => nil) }) }
|
213
213
|
model.should_not have_scope(:no_one).where(:one => 1)
|
214
214
|
end
|
215
215
|
end
|
@@ -4,10 +4,6 @@ module ActiveRecordExampleGroup
|
|
4
4
|
included do
|
5
5
|
metadata[:type] = :active_record
|
6
6
|
|
7
|
-
let(:rake) { Rake::Application.new }
|
8
|
-
let(:task) { rake[self.class.description] }
|
9
|
-
let(:namespace) { self.class.description.split(':').first }
|
10
|
-
|
11
7
|
before do
|
12
8
|
ActiveRecord::Base.establish_connection(
|
13
9
|
:adapter => 'sqlite3',
|
@@ -17,6 +13,7 @@ module ActiveRecordExampleGroup
|
|
17
13
|
end
|
18
14
|
|
19
15
|
RSpec.configure do |config|
|
20
|
-
config.include self,
|
16
|
+
config.include self,
|
17
|
+
:example_group => { :file_path => /spec\/active_record/ }
|
21
18
|
end
|
22
19
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
shared_examples_for 'an Active Record matcher' do
|
2
2
|
let(:matcher_name) { self.class.parent.parent.description }
|
3
3
|
|
4
|
-
def self.with_option(option_name, positive, negative)
|
4
|
+
def self.with_option(option_name, positive, negative, context={})
|
5
5
|
context "with option #{option_name.inspect}" do
|
6
|
-
let(:options) { [:company,
|
6
|
+
let(:options) { [:company, context.merge(option_name => positive)] }
|
7
7
|
|
8
8
|
before { model.send(macro, *options) }
|
9
9
|
|
metadata
CHANGED
@@ -2,73 +2,73 @@
|
|
2
2
|
name: remockable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tyler Hunt
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
+
prerelease: false
|
16
|
+
name: activemodel
|
17
|
+
type: :runtime
|
15
18
|
version_requirements: !ruby/object:Gem::Requirement
|
16
19
|
requirements:
|
17
|
-
- -
|
20
|
+
- - ! '>='
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: '3.0'
|
20
23
|
none: false
|
21
|
-
name: activemodel
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
24
|
requirement: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ! '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '3.0'
|
29
29
|
none: false
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
+
prerelease: false
|
32
|
+
name: activerecord
|
33
|
+
type: :runtime
|
31
34
|
version_requirements: !ruby/object:Gem::Requirement
|
32
35
|
requirements:
|
33
|
-
- -
|
36
|
+
- - ! '>='
|
34
37
|
- !ruby/object:Gem::Version
|
35
38
|
version: '3.0'
|
36
39
|
none: false
|
37
|
-
name: activerecord
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
40
|
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '3.0'
|
45
45
|
none: false
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
+
prerelease: false
|
48
|
+
name: activesupport
|
49
|
+
type: :runtime
|
47
50
|
version_requirements: !ruby/object:Gem::Requirement
|
48
51
|
requirements:
|
49
|
-
- -
|
52
|
+
- - ! '>='
|
50
53
|
- !ruby/object:Gem::Version
|
51
54
|
version: '3.0'
|
52
55
|
none: false
|
53
|
-
name: activesupport
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ! '>='
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
61
|
none: false
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
+
prerelease: false
|
64
|
+
name: rspec-core
|
65
|
+
type: :runtime
|
63
66
|
version_requirements: !ruby/object:Gem::Requirement
|
64
67
|
requirements:
|
65
68
|
- - ~>
|
66
69
|
- !ruby/object:Gem::Version
|
67
70
|
version: '2.0'
|
68
71
|
none: false
|
69
|
-
name: rspec-core
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,15 +76,15 @@ dependencies:
|
|
76
76
|
version: '2.0'
|
77
77
|
none: false
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
+
prerelease: false
|
80
|
+
name: rspec-expectations
|
81
|
+
type: :runtime
|
79
82
|
version_requirements: !ruby/object:Gem::Requirement
|
80
83
|
requirements:
|
81
84
|
- - ~>
|
82
85
|
- !ruby/object:Gem::Version
|
83
86
|
version: '2.0'
|
84
87
|
none: false
|
85
|
-
name: rspec-expectations
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ~>
|
@@ -92,15 +92,15 @@ dependencies:
|
|
92
92
|
version: '2.0'
|
93
93
|
none: false
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
+
prerelease: false
|
96
|
+
name: rspec-mocks
|
97
|
+
type: :runtime
|
95
98
|
version_requirements: !ruby/object:Gem::Requirement
|
96
99
|
requirements:
|
97
100
|
- - ~>
|
98
101
|
- !ruby/object:Gem::Version
|
99
102
|
version: '2.0'
|
100
103
|
none: false
|
101
|
-
name: rspec-mocks
|
102
|
-
type: :runtime
|
103
|
-
prerelease: false
|
104
104
|
requirement: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
106
|
- - ~>
|
@@ -108,15 +108,31 @@ dependencies:
|
|
108
108
|
version: '2.0'
|
109
109
|
none: false
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
+
prerelease: false
|
112
|
+
name: rake
|
113
|
+
type: :development
|
111
114
|
version_requirements: !ruby/object:Gem::Requirement
|
112
115
|
requirements:
|
113
|
-
- -
|
116
|
+
- - ! '>='
|
114
117
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
118
|
+
version: '0'
|
116
119
|
none: false
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
none: false
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
prerelease: false
|
117
128
|
name: sqlite3
|
118
129
|
type: :development
|
119
|
-
|
130
|
+
version_requirements: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ~>
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.3.4
|
135
|
+
none: false
|
120
136
|
requirement: !ruby/object:Gem::Requirement
|
121
137
|
requirements:
|
122
138
|
- - ~>
|
@@ -132,13 +148,13 @@ files:
|
|
132
148
|
- .gitignore
|
133
149
|
- .rspec
|
134
150
|
- .travis.yml
|
151
|
+
- CHANGELOG.md
|
135
152
|
- Gemfile
|
136
153
|
- LICENSE
|
137
154
|
- README.markdown
|
138
155
|
- Rakefile
|
139
156
|
- lib/remockable.rb
|
140
157
|
- lib/remockable/active_model.rb
|
141
|
-
- lib/remockable/active_model/allow_mass_assignment_of.rb
|
142
158
|
- lib/remockable/active_model/allow_values_for.rb
|
143
159
|
- lib/remockable/active_model/helpers.rb
|
144
160
|
- lib/remockable/active_model/validate_acceptance_of.rb
|
@@ -165,7 +181,6 @@ files:
|
|
165
181
|
- lib/remockable/helpers.rb
|
166
182
|
- lib/remockable/version.rb
|
167
183
|
- remockable.gemspec
|
168
|
-
- spec/active_model/allow_mass_assignment_of_spec.rb
|
169
184
|
- spec/active_model/allow_values_for_spec.rb
|
170
185
|
- spec/active_model/validate_acceptance_of_spec.rb
|
171
186
|
- spec/active_model/validate_confirmation_of_spec.rb
|
@@ -202,12 +217,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
217
|
requirements:
|
203
218
|
- - ! '>='
|
204
219
|
- !ruby/object:Gem::Version
|
220
|
+
segments:
|
221
|
+
- 0
|
222
|
+
hash: 770591509696566118
|
205
223
|
version: '0'
|
206
224
|
none: false
|
207
225
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
226
|
requirements:
|
209
227
|
- - ! '>='
|
210
228
|
- !ruby/object:Gem::Version
|
229
|
+
segments:
|
230
|
+
- 0
|
231
|
+
hash: 770591509696566118
|
211
232
|
version: '0'
|
212
233
|
none: false
|
213
234
|
requirements: []
|
@@ -217,7 +238,6 @@ signing_key:
|
|
217
238
|
specification_version: 3
|
218
239
|
summary: A collection of RSpec matchers for web apps.
|
219
240
|
test_files:
|
220
|
-
- spec/active_model/allow_mass_assignment_of_spec.rb
|
221
241
|
- spec/active_model/allow_values_for_spec.rb
|
222
242
|
- spec/active_model/validate_acceptance_of_spec.rb
|
223
243
|
- spec/active_model/validate_confirmation_of_spec.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
RSpec::Matchers.define(:allow_mass_assignment_of) do |*attribute|
|
2
|
-
@options = attribute.extract_options!
|
3
|
-
@attribute = attribute.shift
|
4
|
-
|
5
|
-
@role = @options[:as] || :default
|
6
|
-
@authorizer = nil
|
7
|
-
|
8
|
-
def authorizer(actual)
|
9
|
-
@authorizer ||= actual.class.active_authorizer
|
10
|
-
@authorizer = @authorizer[@role] if @authorizer.is_a?(Hash)
|
11
|
-
@authorizer
|
12
|
-
end
|
13
|
-
|
14
|
-
match_for_should do |actual|
|
15
|
-
!authorizer(actual).deny?(@attribute)
|
16
|
-
end
|
17
|
-
|
18
|
-
match_for_should_not do |actual|
|
19
|
-
authorizer(actual).deny?(@attribute)
|
20
|
-
end
|
21
|
-
|
22
|
-
failure_message_for_should do |actual|
|
23
|
-
"Expected #{actual.class.name} to #{description}"
|
24
|
-
end
|
25
|
-
|
26
|
-
failure_message_for_should_not do |actual|
|
27
|
-
"Did not expect #{actual.class.name} to #{description}"
|
28
|
-
end
|
29
|
-
|
30
|
-
description do
|
31
|
-
"allow mass-assignment of #{@attribute}"
|
32
|
-
end
|
33
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe :allow_mass_assignment_of do
|
4
|
-
let(:attribute) { :one }
|
5
|
-
let(:options) { {} }
|
6
|
-
let(:matcher_name) { self.class.parent.description }
|
7
|
-
|
8
|
-
let(:model) do
|
9
|
-
build_class(:User) { include ActiveModel::MassAssignmentSecurity }
|
10
|
-
end
|
11
|
-
|
12
|
-
subject { model.new }
|
13
|
-
|
14
|
-
context 'description' do
|
15
|
-
it 'has a custom description' do
|
16
|
-
matcher = allow_mass_assignment_of(attribute)
|
17
|
-
matcher.description.should == "allow mass-assignment of #{attribute}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'failure messages' do
|
22
|
-
let(:matcher) { allow_mass_assignment_of(attribute) }
|
23
|
-
|
24
|
-
before { matcher.matches?(subject) }
|
25
|
-
|
26
|
-
it 'has a custom failure message' do
|
27
|
-
matcher.failure_message_for_should.should ==
|
28
|
-
"Expected #{subject.class.name} to #{matcher.description}"
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'has a custom negative failure message' do
|
32
|
-
matcher.failure_message_for_should_not.should ==
|
33
|
-
"Did not expect #{subject.class.name} to #{matcher.description}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'for accessible' do
|
38
|
-
before { model.attr_accessible(attribute, options) }
|
39
|
-
|
40
|
-
it 'matches if the attribute is accessible' do
|
41
|
-
should allow_mass_assignment_of(:one)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'does not match if the attribute is protected' do
|
45
|
-
should_not allow_mass_assignment_of(:two)
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'with a role' do
|
49
|
-
let(:options) { { :as => :admin } }
|
50
|
-
|
51
|
-
it 'matches if the attribute is accessible' do
|
52
|
-
should allow_mass_assignment_of(:one, :as => :admin)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'does not match if the attribute is protected' do
|
56
|
-
should_not allow_mass_assignment_of(:two, :as => :admin)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context 'for protected' do
|
62
|
-
let(:attribute) { :two }
|
63
|
-
|
64
|
-
before { model.attr_protected(attribute, options) }
|
65
|
-
|
66
|
-
it 'matches if the attribute is accessible' do
|
67
|
-
should allow_mass_assignment_of(:one)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'does not match if the attribute is protected' do
|
71
|
-
should_not allow_mass_assignment_of(:two)
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'with a role' do
|
75
|
-
let(:options) { { :as => :admin } }
|
76
|
-
|
77
|
-
it 'matches if the attribute is accessible' do
|
78
|
-
should allow_mass_assignment_of(:one, :as => :admin)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'does not match if the attribute is protected' do
|
82
|
-
should_not allow_mass_assignment_of(:two, :as => :admin)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|