active_model_serializers_matchers 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdff250da3c22d0ef62bb954ba16dee1c104e219
4
- data.tar.gz: a397b8325dc59ba8311e134976f5e2f9153c27d4
3
+ metadata.gz: aebf6c344b00ad0333dcd6cb258c6c1a76037897
4
+ data.tar.gz: 44d578eab83b1f8766cb31358fcacadcfc056289
5
5
  SHA512:
6
- metadata.gz: aa6974f144039465c6c7eae168743c877af1ba9e54fd0ee28774802ca5a1b4e2533a89e0a8cd03cca100fb0def75ac0382932e87443574d56b50317ec70b4c43
7
- data.tar.gz: 847ef0c6e2f1d8685294e61f51337d4ccf6663e16c0bc3f6a131b6588ac1cf9b60f1ca2ab47e5f5d6f60eb0ee6fe6072b910cfe97f70b5f4327ab971754481c4
6
+ metadata.gz: 324fbdb1a050601a50eaa0b949660c91e7a7e00cc702cfeedbce03ffbb6883c4fb6d19e2511d35a20f1d812539847453fa32ff92a458daf36be7d88d36044fa8
7
+ data.tar.gz: df4d83517d5011d9c858ccea3555a7f9922ef71eff6a1c756decb49d515dacbaed82f4d9621170c941c308310842d4628d5043968be555edb2b7f2e0f5972d9d
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # ActiveModelSerializersMatchers
2
2
 
3
- TODO: Write a gem description
3
+ RSpec matchers for testing ActiveModel::Serializer
4
4
 
5
5
  ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'active_model_serializers_matchers'
10
+ gem 'active_model_serializers_matchers', '0.0.1',
11
+ git: 'git://github.com/tonyta/active_model_serializers_matchers.git'
11
12
  ```
12
13
 
13
14
  And then execute:
@@ -24,7 +25,7 @@ TODO: Write usage instructions here
24
25
 
25
26
  ## Contributing
26
27
 
27
- 1. Fork it ( https://github.com/[my-github-username]/active_model_serializers_matchers/fork )
28
+ 1. Fork it ( https://github.com/tonyta/active_model_serializers_matchers/fork )
28
29
  2. Create your feature branch (`git checkout -b my-new-feature`)
29
30
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
31
  4. Push to the branch (`git push origin my-new-feature`)
@@ -23,4 +23,6 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec-its"
27
+ spec.add_development_dependency "pry-byebug"
26
28
  end
@@ -9,4 +9,8 @@ module ActiveModelSerializersMatchers
9
9
  included do
10
10
  subject { described_class }
11
11
  end
12
+
13
+ def have_many(association_root)
14
+ HaveManyAssociationMatcher.new(association_root)
15
+ end
12
16
  end
@@ -3,7 +3,9 @@ module ActiveModelSerializersMatchers
3
3
  attr_accessor :actual, :root, :key, :serializer, :key_check, :serializer_check
4
4
 
5
5
  def initialize(root)
6
- @root = root
6
+ @root = root
7
+ @key_check = false
8
+ @serializer_check = false
7
9
  end
8
10
 
9
11
  def matches?(actual)
@@ -60,6 +62,7 @@ module ActiveModelSerializersMatchers
60
62
  end
61
63
 
62
64
  def association
65
+ return false if associations[root].nil?
63
66
  associations[root]
64
67
  end
65
68
 
@@ -77,8 +80,4 @@ module ActiveModelSerializersMatchers
77
80
  association.options[:serializer].to_s == serializer.to_s
78
81
  end
79
82
  end
80
-
81
- def have_many(root)
82
- HaveManyAssociationMatcher.new(root)
83
- end
84
83
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveModelSerializersMatchers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,130 @@
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(: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(: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 association, match_root?, match_key?, and match_serializer? are all true' do
28
+ before do
29
+ expect(subject).to receive(:association ) { true }
30
+ expect(subject).to receive(:match_root? ) { true }
31
+ expect(subject).to receive(:match_key? ) { true }
32
+ expect(subject).to receive(:match_serializer?) { true }
33
+ end
34
+ specify { expect(subject.matches?(serializer)).to be true }
35
+ end
36
+
37
+ context 'when any association, match_root?, match_key?, or match_serializer? is false' do
38
+ match_check_methods = [:association, :match_root?, :match_key?, :match_serializer?]
39
+
40
+ match_check_methods.each do |false_method|
41
+ before do
42
+ match_check_methods.each do |method|
43
+ allow(subject).to receive(method) { method == false_method ? false : true }
44
+ end
45
+ end
46
+ specify { expect(subject.matches?(serializer)).to be false }
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#as' do
53
+ it 'should return self' do
54
+ expect(subject.as(:a_key)).to be subject
55
+ end
56
+
57
+ context 'when it is not called' do
58
+ its(:key_check) { should be false }
59
+ its(:key) { should be_nil }
60
+ end
61
+
62
+ context 'when it is called with :a_key' do
63
+ before { subject.as(:a_key) }
64
+ its(:key_check) { should be true }
65
+ its(:key) { should be :a_key }
66
+ end
67
+ end
68
+
69
+ describe '#serialized_with' do
70
+ it 'should return self' do
71
+ expect(subject.serialized_with(:a_serializer)).to be subject
72
+ end
73
+
74
+ context 'when it is not called' do
75
+ its(:serializer_check) { should be false }
76
+ its(:serializer) { should be_nil }
77
+ end
78
+
79
+ context 'when it is called with :a_serializer' do
80
+ before { subject.serialized_with(:a_serializer) }
81
+ its(:serializer_check) { should be true }
82
+ its(:serializer) { should be :a_serializer }
83
+ end
84
+ end
85
+
86
+ describe 'integration tests' do
87
+ include ActiveModelSerializersMatchers
88
+
89
+ context 'a serializer with many foos' do
90
+ subject do
91
+ Class.new(ActiveModel::Serializer) { has_many :foos }
92
+ end
93
+ it { should have_many(:foos) }
94
+ it { should_not have_many(:bars) }
95
+ it { should_not have_many(:foos).as(:bars) }
96
+ it { should_not have_many(:foos).serialized_with(:baz) }
97
+ end
98
+
99
+ context 'a serializer with many foos as bars' do
100
+ subject do
101
+ Class.new(ActiveModel::Serializer) { has_many :foos, key: :bars }
102
+ end
103
+ it { should have_many(:foos) }
104
+ it { should have_many(:foos).as(:bars) }
105
+ it { should_not have_many(:foos).as(:baz) }
106
+ end
107
+
108
+ context 'a serializer with many foos serialized with baz' do
109
+ subject do
110
+ Class.new(ActiveModel::Serializer) { has_many :foos, serializer: :baz }
111
+ end
112
+ it { should have_many(:foos) }
113
+ it { should have_many(:foos).serialized_with(:baz) }
114
+ it { should_not have_many(:foos).serialized_with(:bars) }
115
+ end
116
+
117
+ context 'a serializer with many foos as bars serialized with baz' do
118
+ subject do
119
+ Class.new(ActiveModel::Serializer) { has_many :foos, key: :bars, serializer: :baz }
120
+ end
121
+ it { should have_many(:foos) }
122
+ it { should have_many(:foos).as(:bars) }
123
+ it { should have_many(:foos).serialized_with(:baz) }
124
+ it { should have_many(:foos).as(:bars).serialized_with(:baz) }
125
+ it { should_not have_many(:fuus).as(:bars).serialized_with(:baz) }
126
+ it { should_not have_many(:foos).as(:bors).serialized_with(:baz) }
127
+ it { should_not have_many(:foos).as(:bars).serialized_with(:biz) }
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveModelSerializersMatchers do
4
+
5
+ include described_class
6
+
7
+ describe '#have_many' do
8
+ it 'instantiates a new HaveManyAssociationMatcher' do
9
+ expect(described_class::HaveManyAssociationMatcher)
10
+ .to receive(:new).with(:association_root)
11
+ have_many(:association_root)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'pry-byebug'
2
+ require 'rspec/its'
3
+ require 'active_model_serializers'
4
+ require 'active_model_serializers_matchers'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_model_serializers_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Ta
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-its
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: These matchers will allow you to test associations between serializers.
70
98
  email:
71
99
  - tonyta.tt@gmail.com
@@ -74,6 +102,7 @@ extensions: []
74
102
  extra_rdoc_files: []
75
103
  files:
76
104
  - ".gitignore"
105
+ - ".rspec"
77
106
  - Gemfile
78
107
  - LICENSE.txt
79
108
  - README.md
@@ -82,6 +111,9 @@ files:
82
111
  - lib/active_model_serializers_matchers.rb
83
112
  - lib/active_model_serializers_matchers/have_many_association_matcher.rb
84
113
  - lib/active_model_serializers_matchers/version.rb
114
+ - spec/active_model_serializers_matchers/have_many_association_matcher_spec.rb
115
+ - spec/active_model_serializers_matchers_spec.rb
116
+ - spec/spec_helper.rb
85
117
  homepage: ''
86
118
  licenses:
87
119
  - MIT
@@ -106,4 +138,7 @@ rubygems_version: 2.4.2
106
138
  signing_key:
107
139
  specification_version: 4
108
140
  summary: RSpec matchers for testing ActiveModel::Serializer
109
- test_files: []
141
+ test_files:
142
+ - spec/active_model_serializers_matchers/have_many_association_matcher_spec.rb
143
+ - spec/active_model_serializers_matchers_spec.rb
144
+ - spec/spec_helper.rb