brainstem 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,18 +10,18 @@ describe Brainstem::Presenter do
10
10
 
11
11
  it "records itself as the presenter for the named class as a string" do
12
12
  @klass.presents "String"
13
- Brainstem.presenter_collection.for(String).should be_a(@klass)
13
+ expect(Brainstem.presenter_collection.for(String)).to be_a(@klass)
14
14
  end
15
15
 
16
16
  it "records itself as the presenter for the given class" do
17
17
  @klass.presents String
18
- Brainstem.presenter_collection.for(String).should be_a(@klass)
18
+ expect(Brainstem.presenter_collection.for(String)).to be_a(@klass)
19
19
  end
20
20
 
21
21
  it "records itself as the presenter for the named classes" do
22
22
  @klass.presents String, Array
23
- Brainstem.presenter_collection.for(String).should be_a(@klass)
24
- Brainstem.presenter_collection.for(Array).should be_a(@klass)
23
+ expect(Brainstem.presenter_collection.for(String)).to be_a(@klass)
24
+ expect(Brainstem.presenter_collection.for(Array)).to be_a(@klass)
25
25
  end
26
26
  end
27
27
 
@@ -33,12 +33,12 @@ describe Brainstem::Presenter do
33
33
 
34
34
  it "uses the closest module name as the presenter namespace" do
35
35
  V1::SomePresenter.presents String
36
- Brainstem.presenter_collection(:v1).for(String).should be_a(V1::SomePresenter)
36
+ expect(Brainstem.presenter_collection(:v1).for(String)).to be_a(V1::SomePresenter)
37
37
  end
38
38
 
39
39
  it "does not map namespaced presenters into the default namespace" do
40
40
  V1::SomePresenter.presents String
41
- Brainstem.presenter_collection.for(String).should be_nil
41
+ expect(Brainstem.presenter_collection.for(String)).to be_nil
42
42
  end
43
43
  end
44
44
 
@@ -57,10 +57,10 @@ describe Brainstem::Presenter do
57
57
  end
58
58
 
59
59
  it "includes and extends the given module" do
60
- lambda { @klass.new.call_helper }.should raise_error
60
+ expect { @klass.new.call_helper }.to raise_error
61
61
  @klass.helper @helper
62
- @klass.new.call_helper.should == "I work"
63
- @klass.foo.should == "I work"
62
+ expect(@klass.new.call_helper).to eq("I work")
63
+ expect(@klass.foo).to eq("I work")
64
64
  end
65
65
  end
66
66
 
@@ -71,13 +71,13 @@ describe Brainstem::Presenter do
71
71
 
72
72
  it "creates an entry in the filters class ivar" do
73
73
  @klass.filter(:foo, :default => true) { 1 }
74
- @klass.filters[:foo][0].should eq({"default" => true})
75
- @klass.filters[:foo][1].should be_a(Proc)
74
+ expect(@klass.filters[:foo][0]).to eq({"default" => true})
75
+ expect(@klass.filters[:foo][1]).to be_a(Proc)
76
76
  end
77
77
 
78
78
  it "accepts names without blocks" do
79
79
  @klass.filter(:foo)
80
- @klass.filters[:foo][1].should be_nil
80
+ expect(@klass.filters[:foo][1]).to be_nil
81
81
  end
82
82
  end
83
83
 
@@ -88,7 +88,7 @@ describe Brainstem::Presenter do
88
88
 
89
89
  it "creates an entry in the search class ivar" do
90
90
  @klass.search do end
91
- @klass.search_block.should be_a(Proc)
91
+ expect(@klass.search_block).to be_a(Proc)
92
92
  end
93
93
  end
94
94
  end
@@ -112,8 +112,8 @@ describe Brainstem::Presenter do
112
112
 
113
113
  it "outputs the associated object's id and type" do
114
114
  data = @presenter.present_and_post_process(@post)
115
- data[:id].should eq(@post.id.to_s)
116
- data[:body].should eq(@post.body)
115
+ expect(data[:id]).to eq(@post.id.to_s)
116
+ expect(data[:body]).to eq(@post.body)
117
117
  end
118
118
  end
119
119
 
@@ -137,12 +137,12 @@ describe Brainstem::Presenter do
137
137
  iso8601_date = /\d{4}-\d{2}-\d{2}/
138
138
 
139
139
  struct = TimePresenter.new.present_and_post_process("something")
140
- struct[:time].should =~ iso8601_time
141
- struct[:date].should =~ iso8601_date
142
- struct[:recursion][:time].should =~ iso8601_time
143
- struct[:recursion][:something].first.should =~ iso8601_time
144
- struct[:recursion][:something].last.should == :else
145
- struct[:recursion][:foo].should == :bar
140
+ expect(struct[:time]).to match(iso8601_time)
141
+ expect(struct[:date]).to match(iso8601_date)
142
+ expect(struct[:recursion][:time]).to match(iso8601_time)
143
+ expect(struct[:recursion][:something].first).to match(iso8601_time)
144
+ expect(struct[:recursion][:something].last).to eq(:else)
145
+ expect(struct[:recursion][:foo]).to eq(:bar)
146
146
  end
147
147
  end
148
148
 
@@ -155,25 +155,48 @@ describe Brainstem::Presenter do
155
155
  {
156
156
  :body => model.body,
157
157
  :subject => association(:subject),
158
- :another_subject => association(:subject)
158
+ :another_subject => association(:subject),
159
+ :something_else => association(:subject, :ignore_type => true)
159
160
  }
160
161
  end
161
162
  end
162
163
 
163
164
  @presenter = some_presenter.new
164
- @post = Post.first
165
165
  end
166
166
 
167
- it "outputs the associated object's id and type" do
168
- data = @presenter.present_and_post_process(@post)
169
- data[:subject_id].should eq(@post.subject_id.to_s)
170
- data[:subject_type].should eq(@post.subject_type)
167
+ let(:presented_data) { @presenter.present_and_post_process(post) }
168
+
169
+ context "when polymorphic association exists" do
170
+ let(:post) { Post.find(1) }
171
+
172
+
173
+ it "outputs the object as a hash with the id & class table name" do
174
+ expect(presented_data[:subject_ref]).to eq({ :id => post.subject.id.to_s,
175
+ :key => post.subject.class.table_name })
176
+ end
177
+
178
+ it "outputs custom names for the object as a hash with the id & class table name" do
179
+ expect(presented_data[:another_subject_ref]).to eq({ :id => post.subject.id.to_s,
180
+ :key => post.subject.class.table_name })
181
+ end
182
+
183
+ it "skips the polymorphic handling when ignore_type is true" do
184
+ expect(presented_data[:something_else_id]).to eq(post.subject.id.to_s)
185
+ expect(presented_data).not_to have_key(:something_else_type)
186
+ expect(presented_data).not_to have_key(:something_else_ref)
187
+ end
171
188
  end
172
189
 
173
- it "outputs custom names for an associated object's id and type" do
174
- data = @presenter.present_and_post_process(@post)
175
- data[:another_subject_id].should eq(@post.subject_id.to_s)
176
- data[:another_subject_type].should eq(@post.subject_type)
190
+ context "when polymorphic association does not exist" do
191
+ let(:post) { Post.find(3) }
192
+
193
+ it "outputs nil" do
194
+ expect(presented_data[:subject_ref]).to be_nil
195
+ end
196
+
197
+ it "outputs nil" do
198
+ expect(presented_data[:another_subject_ref]).to be_nil
199
+ end
177
200
  end
178
201
  end
179
202
 
@@ -202,43 +225,43 @@ describe Brainstem::Presenter do
202
225
 
203
226
  it "should not convert or return non-included associations, but should return <association>_id for belongs_to relationships, plus all fields" do
204
227
  json = @presenter.present_and_post_process(@workspace, [])
205
- json.keys.should =~ [:id, :updated_at, :something_id, :user_id]
228
+ expect(json.keys).to match_array([:id, :updated_at, :something_id, :user_id])
206
229
  end
207
230
 
208
231
  it "should convert requested has_many associations (includes) into the <association>_ids format" do
209
- @workspace.tasks.length.should > 0
210
- @presenter.present_and_post_process(@workspace, ["tasks"])[:task_ids].should =~ @workspace.tasks.map(&:id).map(&:to_s)
232
+ expect(@workspace.tasks.length).to be > 0
233
+ expect(@presenter.present_and_post_process(@workspace, ["tasks"])[:task_ids]).to match_array(@workspace.tasks.map(&:id).map(&:to_s))
211
234
  end
212
235
 
213
236
  it "should convert requested belongs_to and has_one associations into the <association>_id format when requested" do
214
- @presenter.present_and_post_process(@workspace, ["user"])[:user_id].should == @workspace.user.id.to_s
237
+ expect(@presenter.present_and_post_process(@workspace, ["user"])[:user_id]).to eq(@workspace.user.id.to_s)
215
238
  end
216
239
 
217
240
  it "converts non-association models into <model>_id format when they are requested" do
218
- @presenter.present_and_post_process(@workspace, ["lead_user"])[:lead_user_id].should == @workspace.lead_user.id.to_s
241
+ expect(@presenter.present_and_post_process(@workspace, ["lead_user"])[:lead_user_id]).to eq(@workspace.lead_user.id.to_s)
219
242
  end
220
243
 
221
244
  it "handles associations provided with lambdas" do
222
- @presenter.present_and_post_process(@workspace, ["lead_user_with_lambda"])[:lead_user_with_lambda_id].should == @workspace.lead_user.id.to_s
223
- @presenter.present_and_post_process(@workspace, ["tasks_with_lambda"])[:tasks_with_lambda_ids].should == @workspace.tasks.map(&:id).map(&:to_s)
245
+ expect(@presenter.present_and_post_process(@workspace, ["lead_user_with_lambda"])[:lead_user_with_lambda_id]).to eq(@workspace.lead_user.id.to_s)
246
+ expect(@presenter.present_and_post_process(@workspace, ["tasks_with_lambda"])[:tasks_with_lambda_ids]).to eq(@workspace.tasks.map(&:id).map(&:to_s))
224
247
  end
225
248
 
226
249
  it "should return <association>_id fields when the given association ids exist on the model whether it is requested or not" do
227
- @presenter.present_and_post_process(@workspace, ["user"])[:user_id].should == @workspace.user_id.to_s
250
+ expect(@presenter.present_and_post_process(@workspace, ["user"])[:user_id]).to eq(@workspace.user_id.to_s)
228
251
 
229
252
  json = @presenter.present_and_post_process(@workspace, [])
230
- json.keys.should =~ [:user_id, :something_id, :id, :updated_at]
231
- json[:user_id].should == @workspace.user_id.to_s
232
- json[:something_id].should == @workspace.user_id.to_s
253
+ expect(json.keys).to match_array([:user_id, :something_id, :id, :updated_at])
254
+ expect(json[:user_id]).to eq(@workspace.user_id.to_s)
255
+ expect(json[:something_id]).to eq(@workspace.user_id.to_s)
233
256
  end
234
257
 
235
258
  it "should return null, not empty string when ids are missing" do
236
259
  @workspace.user = nil
237
260
  @workspace.tasks = []
238
- @presenter.present_and_post_process(@workspace, ["lead_user_with_lambda"])[:lead_user_with_lambda_id].should == nil
239
- @presenter.present_and_post_process(@workspace, ["user"])[:user_id].should == nil
240
- @presenter.present_and_post_process(@workspace, ["something"])[:something_id].should == nil
241
- @presenter.present_and_post_process(@workspace, ["tasks"])[:task_ids].should == []
261
+ expect(@presenter.present_and_post_process(@workspace, ["lead_user_with_lambda"])[:lead_user_with_lambda_id]).to eq(nil)
262
+ expect(@presenter.present_and_post_process(@workspace, ["user"])[:user_id]).to eq(nil)
263
+ expect(@presenter.present_and_post_process(@workspace, ["something"])[:something_id]).to eq(nil)
264
+ expect(@presenter.present_and_post_process(@workspace, ["tasks"])[:task_ids]).to eq([])
242
265
  end
243
266
 
244
267
  context "when the model has an <association>_id method but no column" do
@@ -246,7 +269,7 @@ describe Brainstem::Presenter do
246
269
  def @workspace.synthetic_id
247
270
  raise "this explodes because it's not an association"
248
271
  end
249
- @presenter.present_and_post_process(@workspace, []).should_not have_key(:synthetic_id)
272
+ expect(@presenter.present_and_post_process(@workspace, [])).not_to have_key(:synthetic_id)
250
273
  end
251
274
  end
252
275
  end
@@ -4,22 +4,22 @@ describe Brainstem do
4
4
  describe "default_namespace attribute" do
5
5
  it "can be set and read" do
6
6
  Brainstem.default_namespace = "something"
7
- Brainstem.default_namespace.should eq("something")
7
+ expect(Brainstem.default_namespace).to eq("something")
8
8
  end
9
9
 
10
10
  it "returns 'none' if unset" do
11
- Brainstem.default_namespace.should eq("none")
11
+ expect(Brainstem.default_namespace).to eq("none")
12
12
  end
13
13
  end
14
14
 
15
15
  describe "presenter collection method" do
16
16
  it "returns an instance of PresenterCollection" do
17
- Brainstem.presenter_collection.should be_a(Brainstem::PresenterCollection)
17
+ expect(Brainstem.presenter_collection).to be_a(Brainstem::PresenterCollection)
18
18
  end
19
19
 
20
20
  it "accepts a namespace" do
21
- Brainstem.presenter_collection("v1").should be_a(Brainstem::PresenterCollection)
22
- Brainstem.presenter_collection("v1").should_not eq(Brainstem.presenter_collection)
21
+ expect(Brainstem.presenter_collection("v1")).to be_a(Brainstem::PresenterCollection)
22
+ expect(Brainstem.presenter_collection("v1")).not_to eq(Brainstem.presenter_collection)
23
23
  end
24
24
  end
25
25
  end
@@ -76,4 +76,5 @@ Task.create!(:id => 3, :workspace_id => 1, :parent_id => 2, :name => "Green pref
76
76
  Task.create!(:id => 4, :workspace_id => 1, :parent_id => 2, :name => "One bunch")
77
77
 
78
78
  Post.create!(:id => 1, :subject => Workspace.first, :body => "first post!")
79
- Post.create!(:id => 2, :subject => Task.first, :body => "this is important. get on it!")
79
+ Post.create!(:id => 2, :subject => Task.first, :body => "this is important. get on it!")
80
+ Post.create!(:id => 3, :body => "Post without subject")
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainstem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
5
- prerelease:
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mavenlink
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-11-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
- version: '3.0'
19
+ version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
29
- version: '3.0'
26
+ version: '3.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: redcarpet
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rr
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: sqlite3
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: yard
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -131,27 +116,24 @@ executables: []
131
116
  extensions: []
132
117
  extra_rdoc_files: []
133
118
  files:
134
- - brainstem.gemspec
135
119
  - CHANGELOG.md
136
120
  - Gemfile
137
121
  - Gemfile.lock
138
122
  - Guardfile
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - brainstem.gemspec
127
+ - lib/brainstem.rb
139
128
  - lib/brainstem/association_field.rb
140
129
  - lib/brainstem/controller_methods.rb
141
130
  - lib/brainstem/engine.rb
142
131
  - lib/brainstem/presenter.rb
143
132
  - lib/brainstem/presenter_collection.rb
144
133
  - lib/brainstem/search_unavailable_error.rb
134
+ - lib/brainstem/test_helpers.rb
145
135
  - lib/brainstem/time_classes.rb
146
136
  - lib/brainstem/version.rb
147
- - lib/brainstem.rb
148
- - LICENSE
149
- - pkg/brainstem-0.0.2.gem
150
- - pkg/brainstem-0.2.1.gem
151
- - pkg/brainstem-0.2.2.gem
152
- - pkg/brainstem-0.2.gem
153
- - Rakefile
154
- - README.md
155
137
  - spec/brainstem/controller_methods_spec.rb
156
138
  - spec/brainstem/presenter_collection_spec.rb
157
139
  - spec/brainstem/presenter_spec.rb
@@ -163,33 +145,26 @@ files:
163
145
  homepage: http://github.com/mavenlink/brainstem
164
146
  licenses:
165
147
  - MIT
148
+ metadata: {}
166
149
  post_install_message:
167
150
  rdoc_options: []
168
151
  require_paths:
169
152
  - lib
170
153
  required_ruby_version: !ruby/object:Gem::Requirement
171
- none: false
172
154
  requirements:
173
155
  - - ! '>='
174
156
  - !ruby/object:Gem::Version
175
157
  version: '0'
176
- segments:
177
- - 0
178
- hash: 1278718761883180932
179
158
  required_rubygems_version: !ruby/object:Gem::Requirement
180
- none: false
181
159
  requirements:
182
160
  - - ! '>='
183
161
  - !ruby/object:Gem::Version
184
162
  version: '0'
185
- segments:
186
- - 0
187
- hash: 1278718761883180932
188
163
  requirements: []
189
164
  rubyforge_project:
190
- rubygems_version: 1.8.25
165
+ rubygems_version: 2.2.2
191
166
  signing_key:
192
- specification_version: 3
167
+ specification_version: 4
193
168
  summary: ActiveRecord presenters with a rich request API
194
169
  test_files:
195
170
  - spec/brainstem/controller_methods_spec.rb