active_model_serializers_matchers 0.0.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveModelSerializersMatchers::HaveManyAssociationMatcher do
4
-
5
- subject { described_class.new(:foos) }
6
-
7
- let(:serializer) { Class.new(ActiveModel::Serializer) }
8
-
9
- describe '#matches?' do
10
- context 'when called with a class' do
11
- it 'sets @actual to that class' do
12
- allow(subject).to receive(:root_association)
13
- subject.matches?(Object)
14
- expect(subject.actual).to be Object
15
- end
16
- end
17
-
18
- context 'when called with an instance of class' do
19
- it 'sets @actual to the class of that instance' do
20
- allow(subject).to receive(:root_association)
21
- subject.matches?(Object.new)
22
- expect(subject.actual).to be Object
23
- end
24
- end
25
-
26
- describe 'return value' do
27
- context 'when match_association?, match_key?, and match_serializer? are all true' do
28
- before do
29
- expect(subject).to receive(:match_association?) { true }
30
- expect(subject).to receive(:match_key? ) { true }
31
- expect(subject).to receive(:match_serializer? ) { true }
32
- end
33
- specify { expect(subject.matches?(serializer)).to be true }
34
- end
35
-
36
- context 'when any match_association?, match_key?, or match_serializer? is false' do
37
- match_check_methods = [:match_association?, :match_key?, :match_serializer?]
38
-
39
- match_check_methods.each do |false_method|
40
- before do
41
- match_check_methods.each do |method|
42
- allow(subject).to receive(method) { method == false_method ? false : true }
43
- end
44
- end
45
- specify { expect(subject.matches?(serializer)).to be false }
46
- end
47
- end
48
- end
49
- end
50
-
51
- describe '#as' do
52
- it 'should return self' do
53
- expect(subject.as(:a_key)).to be subject
54
- end
55
-
56
- context 'when it is not called' do
57
- its(:key_check) { should be false }
58
- its(:key) { should be_nil }
59
- end
60
-
61
- context 'when it is called with :a_key' do
62
- before { subject.as(:a_key) }
63
- its(:key_check) { should be true }
64
- its(:key) { should be :a_key }
65
- end
66
- end
67
-
68
- describe '#serialized_with' do
69
- it 'should return self' do
70
- expect(subject.serialized_with(:a_serializer)).to be subject
71
- end
72
-
73
- context 'when it is not called' do
74
- its(:serializer_check) { should be false }
75
- its(:serializer) { should be_nil }
76
- end
77
-
78
- context 'when it is called with :a_serializer' do
79
- before { subject.serialized_with(:a_serializer) }
80
- its(:serializer_check) { should be true }
81
- its(:serializer) { should be :a_serializer }
82
- end
83
- end
84
-
85
- describe 'feature tests' do
86
- include ActiveModelSerializersMatchers
87
-
88
- context 'a serializer with one foo' do
89
- subject do
90
- Class.new(ActiveModel::Serializer) { has_one :foo }
91
- end
92
- it { should_not have_many :foo }
93
- it { should_not have_many :foos }
94
- end
95
-
96
- context 'a serializer with many foos' do
97
- subject do
98
- Class.new(ActiveModel::Serializer) { has_many :foos }
99
- end
100
- it { should have_many(:foos) }
101
- it { should_not have_many(:bars) }
102
- it { should_not have_many(:foos).as(:bars) }
103
- it { should_not have_many(:foos).serialized_with(:baz) }
104
- end
105
-
106
- context 'a serializer with many foos as bars' do
107
- subject do
108
- Class.new(ActiveModel::Serializer) { has_many :foos, key: :bars }
109
- end
110
- it { should have_many(:foos) }
111
- it { should have_many(:foos).as(:bars) }
112
- it { should_not have_many(:foos).as(:baz) }
113
- end
114
-
115
- context 'a serializer with many foos serialized with baz' do
116
- subject do
117
- Class.new(ActiveModel::Serializer) { has_many :foos, serializer: :baz }
118
- end
119
- it { should have_many(:foos) }
120
- it { should have_many(:foos).serialized_with(:baz) }
121
- it { should_not have_many(:foos).serialized_with(:bars) }
122
- end
123
-
124
- context 'a serializer with many foos as bars serialized with baz' do
125
- subject do
126
- Class.new(ActiveModel::Serializer) { has_many :foos, key: :bars, serializer: :baz }
127
- end
128
- it { should have_many(:foos) }
129
- it { should have_many(:foos).as(:bars) }
130
- it { should have_many(:foos).serialized_with(:baz) }
131
- it { should have_many(:foos).as(:bars).serialized_with(:baz) }
132
- it { should_not have_many(:fuus).as(:bars).serialized_with(:baz) }
133
- it { should_not have_many(:foos).as(:bors).serialized_with(:baz) }
134
- it { should_not have_many(:foos).as(:bars).serialized_with(:biz) }
135
- end
136
- end
137
- end
@@ -1,137 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveModelSerializersMatchers::HaveOneAssociationMatcher do
4
-
5
- subject { described_class.new(:foos) }
6
-
7
- let(:serializer) { Class.new(ActiveModel::Serializer) }
8
-
9
- describe '#matches?' do
10
- context 'when called with a class' do
11
- it 'sets @actual to that class' do
12
- allow(subject).to receive(:root_association)
13
- subject.matches?(Object)
14
- expect(subject.actual).to be Object
15
- end
16
- end
17
-
18
- context 'when called with an instance of class' do
19
- it 'sets @actual to the class of that instance' do
20
- allow(subject).to receive(:root_association)
21
- subject.matches?(Object.new)
22
- expect(subject.actual).to be Object
23
- end
24
- end
25
-
26
- describe 'return value' do
27
- context 'when match_association?, match_key?, and match_serializer? are all true' do
28
- before do
29
- expect(subject).to receive(:match_association?) { true }
30
- expect(subject).to receive(:match_key? ) { true }
31
- expect(subject).to receive(:match_serializer? ) { true }
32
- end
33
- specify { expect(subject.matches?(serializer)).to be true }
34
- end
35
-
36
- context 'when any match_association?, match_key?, or match_serializer? is false' do
37
- match_check_methods = [:match_association?, :match_key?, :match_serializer?]
38
-
39
- match_check_methods.each do |false_method|
40
- before do
41
- match_check_methods.each do |method|
42
- allow(subject).to receive(method) { method == false_method ? false : true }
43
- end
44
- end
45
- specify { expect(subject.matches?(serializer)).to be false }
46
- end
47
- end
48
- end
49
- end
50
-
51
- describe '#as' do
52
- it 'should return self' do
53
- expect(subject.as(:a_key)).to be subject
54
- end
55
-
56
- context 'when it is not called' do
57
- its(:key_check) { should be false }
58
- its(:key) { should be_nil }
59
- end
60
-
61
- context 'when it is called with :a_key' do
62
- before { subject.as(:a_key) }
63
- its(:key_check) { should be true }
64
- its(:key) { should be :a_key }
65
- end
66
- end
67
-
68
- describe '#serialized_with' do
69
- it 'should return self' do
70
- expect(subject.serialized_with(:a_serializer)).to be subject
71
- end
72
-
73
- context 'when it is not called' do
74
- its(:serializer_check) { should be false }
75
- its(:serializer) { should be_nil }
76
- end
77
-
78
- context 'when it is called with :a_serializer' do
79
- before { subject.serialized_with(:a_serializer) }
80
- its(:serializer_check) { should be true }
81
- its(:serializer) { should be :a_serializer }
82
- end
83
- end
84
-
85
- describe 'feature tests' do
86
- include ActiveModelSerializersMatchers
87
-
88
- context 'a serializer with one foo' do
89
- subject do
90
- Class.new(ActiveModel::Serializer) { has_many :foos }
91
- end
92
- it { should_not have_one :foo }
93
- it { should_not have_one :foos }
94
- end
95
-
96
- context 'a serializer with one foo' do
97
- subject do
98
- Class.new(ActiveModel::Serializer) { has_one :foo }
99
- end
100
- it { should have_one(:foo) }
101
- it { should_not have_one(:bar) }
102
- it { should_not have_one(:foo).as(:bar) }
103
- it { should_not have_one(:foo).serialized_with(:baz) }
104
- end
105
-
106
- context 'a serializer with one foo as bar' do
107
- subject do
108
- Class.new(ActiveModel::Serializer) { has_one :foo, key: :bar }
109
- end
110
- it { should have_one(:foo) }
111
- it { should have_one(:foo).as(:bar) }
112
- it { should_not have_one(:foo).as(:baz) }
113
- end
114
-
115
- context 'a serializer with one foo serialized with baz' do
116
- subject do
117
- Class.new(ActiveModel::Serializer) { has_one :foo, serializer: :baz }
118
- end
119
- it { should have_one(:foo) }
120
- it { should have_one(:foo).serialized_with(:baz) }
121
- it { should_not have_one(:foo).serialized_with(:bar) }
122
- end
123
-
124
- context 'a serializer with one foo as bar serialized with baz' do
125
- subject do
126
- Class.new(ActiveModel::Serializer) { has_one :foo, key: :bar, serializer: :baz }
127
- end
128
- it { should have_one(:foo) }
129
- it { should have_one(:foo).as(:bar) }
130
- it { should have_one(:foo).serialized_with(:baz) }
131
- it { should have_one(:foo).as(:bar).serialized_with(:baz) }
132
- it { should_not have_one(:fuu).as(:bar).serialized_with(:baz) }
133
- it { should_not have_one(:foo).as(:bor).serialized_with(:baz) }
134
- it { should_not have_one(:foo).as(:bar).serialized_with(:biz) }
135
- end
136
- end
137
- end