serialization_scopes 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module SerializationScopes # :nodoc:
|
2
|
+
module Shoulda # :nodoc:
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
# Ensures that records are serialized correctly
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
# describe Article do
|
9
|
+
# it { should serialize }
|
10
|
+
# it { should serialize.to(:article) }
|
11
|
+
# it { should serialize.to(:article).with_attributes(6) }
|
12
|
+
# it { should serialize.for(:reader).to(:article).with_attributes(4) }
|
13
|
+
# end
|
14
|
+
def serialize
|
15
|
+
SerializeMatcher.new
|
16
|
+
end
|
17
|
+
|
18
|
+
class SerializeMatcher
|
19
|
+
|
20
|
+
def for(scope)
|
21
|
+
@scope = scope
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to(value)
|
26
|
+
@to = value
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def with_attributes(count)
|
31
|
+
@count = count
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def matches?(subject)
|
36
|
+
@subject = subject
|
37
|
+
@subject.id ||= rand(10000000)
|
38
|
+
correct_root? && correct_column_count?
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :failure_message, :negative_failure_message
|
42
|
+
|
43
|
+
def description
|
44
|
+
result = "serialize"
|
45
|
+
result << " with #{@scope.inspect} scope" unless @scope.nil?
|
46
|
+
result << " to #{@to.inspect}" unless @to.nil?
|
47
|
+
result << " with #{@count} attributes" unless @count.nil?
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def failure_message
|
52
|
+
"Expected #{expectation}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def negative_failure_message
|
56
|
+
"Did not expect #{expectation}"
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def root_name
|
62
|
+
serialized.keys.first
|
63
|
+
end
|
64
|
+
|
65
|
+
def attributes
|
66
|
+
serialized[root_name] ? serialized[root_name].keys : []
|
67
|
+
end
|
68
|
+
|
69
|
+
def serialized
|
70
|
+
@serialized ||= ActiveSupport::JSON.decode(@subject.to_json(:scope => @scope))
|
71
|
+
end
|
72
|
+
|
73
|
+
def expectation
|
74
|
+
result = "to #{description}"
|
75
|
+
result << ", but #{failure_description}"
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def correct_root?
|
80
|
+
@to.nil? || @to == root_name
|
81
|
+
end
|
82
|
+
|
83
|
+
def correct_column_count?
|
84
|
+
@count.nil? || @count == attributes.size
|
85
|
+
end
|
86
|
+
|
87
|
+
def failure_description
|
88
|
+
if !correct_root?
|
89
|
+
"root was #{root_name.inspect}"
|
90
|
+
elsif !correct_column_count?
|
91
|
+
"#{attributes.size} attributes were created (#{attributes.map(&:to_s).sort.join(', ')})"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{serialization_scopes}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dimitrij Denissenko"]
|
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
25
|
"lib/serialization_scopes.rb",
|
26
|
+
"lib/serialization_scopes/matchers.rb",
|
27
|
+
"lib/serialization_scopes/matchers/serialize_matcher.rb",
|
26
28
|
"rails/init.rb",
|
27
29
|
"serialization_scopes.gemspec",
|
28
30
|
"spec/helper.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serialization_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dimitrij Denissenko
|
@@ -50,6 +50,8 @@ files:
|
|
50
50
|
- Rakefile
|
51
51
|
- VERSION
|
52
52
|
- lib/serialization_scopes.rb
|
53
|
+
- lib/serialization_scopes/matchers.rb
|
54
|
+
- lib/serialization_scopes/matchers/serialize_matcher.rb
|
53
55
|
- rails/init.rb
|
54
56
|
- serialization_scopes.gemspec
|
55
57
|
- spec/helper.rb
|