remockable 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/remockable/active_model/allow_mass_assignment_of.rb +8 -6
- data/lib/remockable/active_model/allow_values_for.rb +36 -0
- data/lib/remockable/active_model.rb +3 -0
- data/lib/remockable/active_record/accept_nested_attributes_for.rb +28 -0
- data/lib/remockable/active_record/have_default_scope.rb +6 -26
- data/lib/remockable/active_record/have_scope.rb +2 -21
- data/lib/remockable/active_record.rb +2 -0
- data/lib/remockable/version.rb +1 -1
- metadata +70 -78
@@ -1,16 +1,18 @@
|
|
1
1
|
RSpec::Matchers.define(:allow_mass_assignment_of) do |*attributes|
|
2
2
|
@attributes = attributes
|
3
3
|
|
4
|
+
def authorizer(actual)
|
5
|
+
@authorizer ||= actual.class.active_authorizer
|
6
|
+
@authorizer = @authorizer[:default] if @authorizer.is_a?(Hash)
|
7
|
+
@authorizer
|
8
|
+
end
|
9
|
+
|
4
10
|
match_for_should do |actual|
|
5
|
-
@attributes.all?
|
6
|
-
!actual.class.active_authorizer.deny?(attribute)
|
7
|
-
end
|
11
|
+
@attributes.all? { |attribute| !authorizer(actual).deny?(attribute) }
|
8
12
|
end
|
9
13
|
|
10
14
|
match_for_should_not do |actual|
|
11
|
-
@attributes.all?
|
12
|
-
actual.class.active_authorizer.deny?(attribute)
|
13
|
-
end
|
15
|
+
@attributes.all? { |attribute| authorizer(actual).deny?(attribute) }
|
14
16
|
end
|
15
17
|
|
16
18
|
failure_message_for_should do |actual|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
RSpec::Matchers.define(:allow_values_for) do |*attributes_and_values|
|
2
|
+
@attribute = attributes_and_values.shift
|
3
|
+
@values = attributes_and_values
|
4
|
+
|
5
|
+
match_for_should do |actual|
|
6
|
+
instance = subject.class.new
|
7
|
+
|
8
|
+
@values.all? do |value|
|
9
|
+
instance.stub(@attribute).and_return(value)
|
10
|
+
instance.valid?
|
11
|
+
instance.errors[@attribute].empty?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
match_for_should_not do |actual|
|
16
|
+
instance = subject.class.new
|
17
|
+
|
18
|
+
@values.none? do |value|
|
19
|
+
instance.stub(@attribute).and_return(value)
|
20
|
+
instance.valid?
|
21
|
+
instance.errors[@attribute].empty?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_for_should do |actual|
|
26
|
+
"Expected #{actual.class.name} to #{description}"
|
27
|
+
end
|
28
|
+
|
29
|
+
failure_message_for_should_not do |actual|
|
30
|
+
"Did not expect #{actual.class.name} to #{description}"
|
31
|
+
end
|
32
|
+
|
33
|
+
description do
|
34
|
+
"allow the values #{@values.collect(&:inspect).to_sentence} for #{@attribute}"
|
35
|
+
end
|
36
|
+
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'remockable/active_model/helpers'
|
2
|
+
|
2
3
|
require 'remockable/active_model/allow_mass_assignment_of'
|
4
|
+
|
5
|
+
require 'remockable/active_model/allow_values_for'
|
3
6
|
require 'remockable/active_model/validate_acceptance_of'
|
4
7
|
require 'remockable/active_model/validate_confirmation_of'
|
5
8
|
require 'remockable/active_model/validate_exclusion_of'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
RSpec::Matchers.define(:accept_nested_attributes_for) do |*attributes|
|
2
|
+
extend Remockable::ActiveRecord::Helpers
|
3
|
+
|
4
|
+
@expected = attributes.extract_options!
|
5
|
+
@association = attributes.first
|
6
|
+
|
7
|
+
unsupported_options %w(reject_if)
|
8
|
+
valid_options %w(allow_destroy limit update_only)
|
9
|
+
|
10
|
+
match do |actual|
|
11
|
+
if options = subject.class.nested_attributes_options[@association]
|
12
|
+
options.slice(*expected.keys) == expected
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
failure_message_for_should do |actual|
|
17
|
+
"Expected #{subject.class.name} to #{description}"
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message_for_should_not do |actual|
|
21
|
+
"Did not expect #{subject.class.name} to #{description}"
|
22
|
+
end
|
23
|
+
|
24
|
+
description do
|
25
|
+
with = " with #{expected.inspect}" if expected.any?
|
26
|
+
"accept nested attributes for #{@association}#{with}"
|
27
|
+
end
|
28
|
+
end
|
@@ -19,7 +19,9 @@ RSpec::Matchers.define(:have_default_scope) do |*expected|
|
|
19
19
|
readonly_matches = scope.readonly_value == @relation.readonly_value
|
20
20
|
|
21
21
|
query_matches && eager_load_matches && includes_matches && lock_matches && preload_matches && readonly_matches
|
22
|
-
elsif subject.class.respond_to?(:
|
22
|
+
elsif subject.class.respond_to?(:default_scopes) # Rails 3.1
|
23
|
+
subject.class.default_scopes.any?
|
24
|
+
elsif subject.class.respond_to?(:default_scoping) # Rails 3.0
|
23
25
|
subject.class.default_scoping.any?
|
24
26
|
end
|
25
27
|
end
|
@@ -27,33 +29,11 @@ RSpec::Matchers.define(:have_default_scope) do |*expected|
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def method_missing(method, *args, &block)
|
30
|
-
|
31
|
-
|
32
|
-
)
|
33
|
-
|
34
|
-
query_methods = %w(
|
35
|
-
eager_load
|
36
|
-
from
|
37
|
-
group
|
38
|
-
having
|
39
|
-
includes
|
40
|
-
joins
|
41
|
-
limit
|
42
|
-
lock
|
43
|
-
offset
|
44
|
-
order
|
45
|
-
preload
|
46
|
-
readonly
|
47
|
-
reorder
|
48
|
-
select
|
49
|
-
where
|
50
|
-
)
|
32
|
+
unsupported_query_methods = %(create_with eager_load includes lock preload readonly)
|
33
|
+
query_methods = %w(from group having joins limit offset order reorder select where)
|
51
34
|
|
52
35
|
if query_methods.include?(method.to_s)
|
53
|
-
@relation ||= subject.class.
|
54
|
-
subject.class.scoped
|
55
|
-
end
|
56
|
-
|
36
|
+
@relation ||= subject.class.unscoped
|
57
37
|
@relation = @relation.send(method, *args)
|
58
38
|
self
|
59
39
|
else
|
@@ -33,27 +33,8 @@ RSpec::Matchers.define(:have_scope) do |*expected|
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def method_missing(method, *args, &block)
|
36
|
-
|
37
|
-
|
38
|
-
)
|
39
|
-
|
40
|
-
query_methods = %w(
|
41
|
-
eager_load
|
42
|
-
from
|
43
|
-
group
|
44
|
-
having
|
45
|
-
includes
|
46
|
-
joins
|
47
|
-
limit
|
48
|
-
lock
|
49
|
-
offset
|
50
|
-
order
|
51
|
-
preload
|
52
|
-
readonly
|
53
|
-
reorder
|
54
|
-
select
|
55
|
-
where
|
56
|
-
)
|
36
|
+
unsupported_query_methods = %(create_with)
|
37
|
+
query_methods = %w(eager_load from group having includes joins limit lock offset order preload readonly reorder select where)
|
57
38
|
|
58
39
|
if query_methods.include?(method.to_s)
|
59
40
|
@relation ||= subject.class.scoped
|
data/lib/remockable/version.rb
CHANGED
metadata
CHANGED
@@ -1,107 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: remockable
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.9
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Tyler Hunt
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: activemodel
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70354128603640 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
18
|
+
requirements:
|
22
19
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: activerecord
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70354128603640
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activerecord
|
27
|
+
requirement: &70354128603140 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
29
|
+
requirements:
|
33
30
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
36
33
|
type: :runtime
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: activesupport
|
40
34
|
prerelease: false
|
41
|
-
|
35
|
+
version_requirements: *70354128603140
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: activesupport
|
38
|
+
requirement: &70354128602680 !ruby/object:Gem::Requirement
|
42
39
|
none: false
|
43
|
-
requirements:
|
40
|
+
requirements:
|
44
41
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.0'
|
47
44
|
type: :runtime
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rspec-core
|
51
45
|
prerelease: false
|
52
|
-
|
46
|
+
version_requirements: *70354128602680
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-core
|
49
|
+
requirement: &70354128602220 !ruby/object:Gem::Requirement
|
53
50
|
none: false
|
54
|
-
requirements:
|
51
|
+
requirements:
|
55
52
|
- - ~>
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version:
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
58
55
|
type: :runtime
|
59
|
-
version_requirements: *id004
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: rspec-expectations
|
62
56
|
prerelease: false
|
63
|
-
|
57
|
+
version_requirements: *70354128602220
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rspec-expectations
|
60
|
+
requirement: &70354128601760 !ruby/object:Gem::Requirement
|
64
61
|
none: false
|
65
|
-
requirements:
|
62
|
+
requirements:
|
66
63
|
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version:
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.0'
|
69
66
|
type: :runtime
|
70
|
-
version_requirements: *id005
|
71
|
-
- !ruby/object:Gem::Dependency
|
72
|
-
name: rspec-mocks
|
73
67
|
prerelease: false
|
74
|
-
|
68
|
+
version_requirements: *70354128601760
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-mocks
|
71
|
+
requirement: &70354128601300 !ruby/object:Gem::Requirement
|
75
72
|
none: false
|
76
|
-
requirements:
|
73
|
+
requirements:
|
77
74
|
- - ~>
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version:
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.0'
|
80
77
|
type: :development
|
81
|
-
version_requirements: *id006
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: sqlite3
|
84
78
|
prerelease: false
|
85
|
-
|
79
|
+
version_requirements: *70354128601300
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: sqlite3
|
82
|
+
requirement: &70354128600840 !ruby/object:Gem::Requirement
|
86
83
|
none: false
|
87
|
-
requirements:
|
84
|
+
requirements:
|
88
85
|
- - ~>
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: 1.3.
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.3.4
|
91
88
|
type: :development
|
92
|
-
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70354128600840
|
93
91
|
description:
|
94
92
|
email:
|
95
93
|
executables: []
|
96
|
-
|
97
94
|
extensions: []
|
98
|
-
|
99
95
|
extra_rdoc_files: []
|
100
|
-
|
101
|
-
files:
|
96
|
+
files:
|
102
97
|
- README.markdown
|
103
98
|
- LICENSE
|
104
99
|
- lib/remockable/active_model/allow_mass_assignment_of.rb
|
100
|
+
- lib/remockable/active_model/allow_values_for.rb
|
105
101
|
- lib/remockable/active_model/helpers.rb
|
106
102
|
- lib/remockable/active_model/validate_acceptance_of.rb
|
107
103
|
- lib/remockable/active_model/validate_confirmation_of.rb
|
@@ -112,6 +108,7 @@ files:
|
|
112
108
|
- lib/remockable/active_model/validate_numericality_of.rb
|
113
109
|
- lib/remockable/active_model/validate_presence_of.rb
|
114
110
|
- lib/remockable/active_model.rb
|
111
|
+
- lib/remockable/active_record/accept_nested_attributes_for.rb
|
115
112
|
- lib/remockable/active_record/belong_to.rb
|
116
113
|
- lib/remockable/active_record/have_and_belong_to_many.rb
|
117
114
|
- lib/remockable/active_record/have_column.rb
|
@@ -127,33 +124,28 @@ files:
|
|
127
124
|
- lib/remockable/helpers.rb
|
128
125
|
- lib/remockable/version.rb
|
129
126
|
- lib/remockable.rb
|
130
|
-
has_rdoc: true
|
131
127
|
homepage: http://github.com/tylerhunt/remockable
|
132
128
|
licenses: []
|
133
|
-
|
134
129
|
post_install_message:
|
135
130
|
rdoc_options: []
|
136
|
-
|
137
|
-
require_paths:
|
131
|
+
require_paths:
|
138
132
|
- lib
|
139
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
134
|
none: false
|
141
|
-
requirements:
|
142
|
-
- -
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version:
|
145
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
140
|
none: false
|
147
|
-
requirements:
|
148
|
-
- -
|
149
|
-
- !ruby/object:Gem::Version
|
150
|
-
version:
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
151
145
|
requirements: []
|
152
|
-
|
153
146
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.6
|
147
|
+
rubygems_version: 1.8.6
|
155
148
|
signing_key:
|
156
149
|
specification_version: 3
|
157
150
|
summary: A collection of RSpec matchers to simplify your web app specs.
|
158
151
|
test_files: []
|
159
|
-
|