remockable 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown
CHANGED
@@ -7,6 +7,8 @@ require 'remockable/active_record/have_one'
|
|
7
7
|
|
8
8
|
require 'remockable/active_record/have_column'
|
9
9
|
require 'remockable/active_record/have_index'
|
10
|
+
|
11
|
+
require 'remockable/active_record/have_default_scope'
|
10
12
|
require 'remockable/active_record/have_scope'
|
11
13
|
|
12
14
|
require 'remockable/active_record/validate_associated'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
RSpec::Matchers.define(:have_default_scope) do |*expected|
|
2
|
+
extend Remockable::ActiveRecord::Helpers
|
3
|
+
|
4
|
+
@expected = expected.extract_options!
|
5
|
+
|
6
|
+
valid_options %w()
|
7
|
+
|
8
|
+
match do |actual|
|
9
|
+
if subject.class.respond_to?(:scoped)
|
10
|
+
scope = subject.class.scoped
|
11
|
+
|
12
|
+
if scope.is_a?(ActiveRecord::Relation)
|
13
|
+
if @relation
|
14
|
+
query_matches = scope.arel.to_sql == @relation.arel.to_sql
|
15
|
+
eager_load_matches = scope.eager_load_values == @relation.eager_load_values
|
16
|
+
includes_matches = scope.includes_values == @relation.includes_values
|
17
|
+
lock_matches = scope.lock_value == @relation.lock_value
|
18
|
+
preload_matches = scope.preload_values == @relation.preload_values
|
19
|
+
readonly_matches = scope.readonly_value == @relation.readonly_value
|
20
|
+
|
21
|
+
query_matches && eager_load_matches && includes_matches && lock_matches && preload_matches && readonly_matches
|
22
|
+
elsif subject.class.respond_to?(:default_scoping)
|
23
|
+
subject.class.default_scoping.any?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(method, *args, &block)
|
30
|
+
unsupposed_query_methods = %(
|
31
|
+
create_with
|
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
|
+
)
|
51
|
+
|
52
|
+
if query_methods.include?(method.to_s)
|
53
|
+
@relation ||= subject.class.send(:with_exclusive_scope) do
|
54
|
+
subject.class.scoped
|
55
|
+
end
|
56
|
+
|
57
|
+
@relation = @relation.send(method, *args)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
super
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
failure_message_for_should do |actual|
|
65
|
+
"Expected #{subject.class.name} to #{description}"
|
66
|
+
end
|
67
|
+
|
68
|
+
failure_message_for_should_not do |actual|
|
69
|
+
"Did not expect #{subject.class.name} to #{description}"
|
70
|
+
end
|
71
|
+
|
72
|
+
description do
|
73
|
+
with = " with #{@expected.inspect}" if @expected.any?
|
74
|
+
"have a default scope#{with}"
|
75
|
+
end
|
76
|
+
end
|
@@ -8,21 +8,21 @@ RSpec::Matchers.define(:have_scope) do |*expected|
|
|
8
8
|
|
9
9
|
match do |actual|
|
10
10
|
if subject.class.respond_to?(@name)
|
11
|
-
|
11
|
+
scope = if @expected.key?(:with)
|
12
12
|
with = Array(@expected[:with])
|
13
13
|
subject.class.send(@name, *with)
|
14
14
|
else
|
15
15
|
subject.class.send(@name)
|
16
16
|
end
|
17
17
|
|
18
|
-
if
|
18
|
+
if scope.is_a?(ActiveRecord::Relation)
|
19
19
|
if @relation
|
20
|
-
query_matches =
|
21
|
-
eager_load_matches =
|
22
|
-
includes_matches =
|
23
|
-
lock_matches =
|
24
|
-
preload_matches =
|
25
|
-
readonly_matches =
|
20
|
+
query_matches = scope.arel.to_sql == @relation.arel.to_sql
|
21
|
+
eager_load_matches = scope.eager_load_values == @relation.eager_load_values
|
22
|
+
includes_matches = scope.includes_values == @relation.includes_values
|
23
|
+
lock_matches = scope.lock_value == @relation.lock_value
|
24
|
+
preload_matches = scope.preload_values == @relation.preload_values
|
25
|
+
readonly_matches = scope.readonly_value == @relation.readonly_value
|
26
26
|
|
27
27
|
query_matches && eager_load_matches && includes_matches && lock_matches && preload_matches && readonly_matches
|
28
28
|
else
|
data/lib/remockable/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: remockable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tyler Hunt
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-05
|
13
|
+
date: 2011-07-05 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/remockable/active_record/belong_to.rb
|
116
116
|
- lib/remockable/active_record/have_and_belong_to_many.rb
|
117
117
|
- lib/remockable/active_record/have_column.rb
|
118
|
+
- lib/remockable/active_record/have_default_scope.rb
|
118
119
|
- lib/remockable/active_record/have_index.rb
|
119
120
|
- lib/remockable/active_record/have_many.rb
|
120
121
|
- lib/remockable/active_record/have_one.rb
|