tms_bridge 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MTAzYWNhZDAzOGU1MDMwYWZiNTk1NTZmOTg1Yzg0MGM5MDYyZGQ2Nw==
5
- data.tar.gz: !binary |-
6
- ZTY1YzI1YWE1ZGJlMzg4NjI0NGQ3ZTMxNjJkYmUxMDAyNjgyMzAxMQ==
2
+ SHA1:
3
+ metadata.gz: cd09e8601f91427278f8d3bfdfaa9523637e8647
4
+ data.tar.gz: 5e01784d862d2dd3ef97acd2b7989f8306f24008
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzU1NDE0NTFiZmUxNjkzZjQwOWU3MWNhMWQ5MDk2YmUyNjc3MGJkNTlkOTg1
10
- N2FhNDUzZDFkODU5MDUxNWE5ZmQyNWI5MThlY2Y0Y2Q2MGI1OGZiMWEyYjIx
11
- MmEyNDFhMzNjOWU0Yjg5MGZiMDJkODUwYjYzNWY1MzkwZTgwMjg=
12
- data.tar.gz: !binary |-
13
- OGQwYWFiMjlmNTQ4ZGU4OTM1ODdhZWUwOGJjM2RkODZhZjA5YWYxMTBiMTBj
14
- ZDZiMGM5ZDIzN2RhZjk2M2Y3NjQ5YzI3M2JlODA1ZDU2YzAyNmU4NmJlYTZk
15
- OGE2NGMwNzkyNWE0NWQ0OTA0Njg2MTk1YzdhYTEyNzlkNDgzNjk=
6
+ metadata.gz: d3b697f342d736f9f2abc266226746d705130dc122546eb116e97d7c64ebffc55e5a1b3a554fd54dd4ef9a3505d4ef90cddab0c94ca84fd4956202ee576ba589
7
+ data.tar.gz: 91eeefd9cce793a2d031ebb31eb5263cca1e9a11176c373f6fddaa13d0e948e2cfb52b96bf489df13cd93c47bf82527bce6fb318bfa44b61e180de82a5b68975
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ config
5
6
  coverage
6
7
  InstalledFiles
7
8
  lib/bundler/man
@@ -1 +1 @@
1
- ruby-1.9.3-p545
1
+ ruby 2.1.7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tms_bridge (0.1.2)
4
+ tms_bridge (0.2.0)
5
5
  actionpack (>= 3.2.0)
6
6
  activerecord (>= 3.2.0)
7
7
  iron_cache
@@ -34,7 +34,7 @@ GEM
34
34
  multi_json (~> 1.0)
35
35
  arel (3.0.2)
36
36
  builder (3.0.4)
37
- diff-lcs (1.2.4)
37
+ diff-lcs (1.2.5)
38
38
  erubis (2.7.0)
39
39
  ethon (0.5.12)
40
40
  ffi (>= 1.3.0)
@@ -61,14 +61,19 @@ GEM
61
61
  rest-client (>= 0.3.0)
62
62
  rest-client (1.6.7)
63
63
  mime-types (>= 1.16)
64
- rspec (2.13.0)
65
- rspec-core (~> 2.13.0)
66
- rspec-expectations (~> 2.13.0)
67
- rspec-mocks (~> 2.13.0)
68
- rspec-core (2.13.1)
69
- rspec-expectations (2.13.0)
70
- diff-lcs (>= 1.1.3, < 2.0)
71
- rspec-mocks (2.13.1)
64
+ rspec (3.4.0)
65
+ rspec-core (~> 3.4.0)
66
+ rspec-expectations (~> 3.4.0)
67
+ rspec-mocks (~> 3.4.0)
68
+ rspec-core (3.4.4)
69
+ rspec-support (~> 3.4.0)
70
+ rspec-expectations (3.4.0)
71
+ diff-lcs (>= 1.2.0, < 2.0)
72
+ rspec-support (~> 3.4.0)
73
+ rspec-mocks (3.4.1)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.4.0)
76
+ rspec-support (3.4.1)
72
77
  sprockets (2.2.2)
73
78
  hike (~> 1.2)
74
79
  multi_json (~> 1.0)
@@ -86,5 +91,8 @@ PLATFORMS
86
91
  DEPENDENCIES
87
92
  bundler (~> 1.3)
88
93
  rake
89
- rspec (~> 2.6)
94
+ rspec (~> 3)
90
95
  tms_bridge!
96
+
97
+ BUNDLED WITH
98
+ 1.11.2
@@ -1,7 +1,9 @@
1
1
  module TmsBridge
2
2
  module ModelSupport
3
3
  def published_attribute_names
4
- self.column_names - %w{id created_at updated_at}
4
+ _attributes_names = self.column_names - %w{id created_at updated_at}
5
+ _attributes_names+=self.attribute_aliases.keys
6
+ return _attributes_names.compact.map(&:to_s).uniq
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -8,22 +8,22 @@ describe IronCacher do
8
8
 
9
9
  describe "iron_cache_client" do
10
10
  it "return an iron cache client instance" do
11
- MockIronCache.iron_cache_client.should be_is_a(IronCache::Client)
11
+ expect(MockIronCache.iron_cache_client).to be_a(IronCache::Client)
12
12
  end
13
13
 
14
14
  it "should use a separate config file from the iron.json" do
15
- MockIronCache.iron_cache_client.project_id.should == JSON.parse(File.read("config/iron.json"))['project_id']
15
+ expect(MockIronCache.iron_cache_client.project_id).to eq(JSON.parse(File.read("config/iron.json"))['project_id'])
16
16
  end
17
17
 
18
18
  end
19
19
 
20
20
  describe "iron_cache" do
21
21
  it "return an iron cache instance" do
22
- MockIronCache.iron_cache.should be_is_a(IronCache::Cache)
22
+ expect(MockIronCache.iron_cache).to be_a(IronCache::Cache)
23
23
  end
24
24
 
25
25
  it "should should return the cache with the name of the as CACHE_NAME" do
26
- MockIronCache.iron_cache.name.should == IronCacher::CACHE_NAME
26
+ expect(MockIronCache.iron_cache.name).to eq(IronCacher::CACHE_NAME)
27
27
  end
28
28
  end
29
29
 
@@ -33,25 +33,25 @@ describe IronCacher do
33
33
  end
34
34
 
35
35
  it "should return the key" do
36
- MockIronCache.add_to_cache(@key, 'value').should == @key
36
+ expect(MockIronCache.add_to_cache(@key, 'value')).to eq(@key)
37
37
  end
38
38
 
39
39
  it "should add an expiry" do
40
40
  MockIronCache.add_to_cache(@key, 'value')
41
41
  expires = MockIronCache.iron_cache.get(@key)['expires']
42
- DateTime.parse(expires).should < DateTime.parse('9999-01-01T00:00:00+00:00')
42
+ expect(DateTime.parse(expires)).to be < DateTime.parse('9999-01-01T00:00:00+00:00')
43
43
  end
44
44
 
45
45
  end
46
46
 
47
47
  describe "random_key_and_value" do
48
48
  it "should return an array" do
49
- MockIronCache.random_key_and_value(IronCacher::CACHE_NAME).class.should == Array
49
+ expect(MockIronCache.random_key_and_value(IronCacher::CACHE_NAME).class).to eq(Array)
50
50
  end
51
51
 
52
52
  it "should return the key as the first element and value in cache as the second" do
53
53
  key,value = MockIronCache.random_key_and_value(IronCacher::CACHE_NAME)
54
- MockIronCache.iron_cache.get(key).value.should == value
54
+ expect(MockIronCache.iron_cache.get(key).value).to eq(value)
55
55
  end
56
56
  end
57
57
 
@@ -10,27 +10,28 @@ describe TmsBridge::ControllerSupport::Security do
10
10
  secure_tms_bridge :some_client
11
11
  end
12
12
 
13
- describe "class attributes" do
14
- it "should define and set 'as' " do
15
- SecuritiesController.as.should == 'some_client'
16
- end
17
-
18
- it "should define and set 'bridged_resource' " do
19
- SecuritiesController.bridged_resource.should == 'security'
20
- end
21
-
22
- it "should define and set 'bridged_resources' " do
23
- SecuritiesController.bridged_resources.should == 'securities'
24
- end
25
-
26
- it "should define and set 'queue_name' " do
27
- SecuritiesController.queue_name.should == 'some_client_securities'
28
- end
29
-
30
- it "should add :parse_iron_mq_json to the before_filters" do
31
- SecuritiesController.before_filters.should include(:parse_iron_mq_json)
32
- end
33
- end
13
+ # describe "class attributes" do
14
+ # it "should define and set 'as' " do
15
+ # expect(SecuritiesController.as).to eq 'some_client'
16
+ # end
17
+ #
18
+ # it "should define and set 'bridged_resource' " do
19
+ # expect(SecuritiesController.bridged_resource).to eq 'security'
20
+ # end
21
+ #
22
+ # it "should define and set 'bridged_resources' " do
23
+ # expect(SecuritiesController.bridged_resources).to eq 'securities'
24
+ # end
25
+ #
26
+ # it "should define and set 'queue_name' " do
27
+ # expect(SecuritiesController.queue_name).to eq 'some_client_securities'
28
+ # end
29
+ #
30
+ # it "should add :parse_iron_mq_json to the before_filters" do
31
+ # expect(SecuritiesController.before_filters).to include(:parse_iron_mq_json)
32
+ # end
33
+ # end
34
+
34
35
  describe "validate_bridge_request?" do
35
36
  before(:each) do
36
37
  @cache_key = 'cache_key'
@@ -39,314 +40,312 @@ describe TmsBridge::ControllerSupport::Security do
39
40
  yield if block_given?
40
41
  add_to_cache(@cache_key, @digest)
41
42
  end
42
- def controller
43
- @controller ||= SecuritiesController.new
44
- end
43
+ let(:controller) { SecuritiesController.new }
45
44
 
46
45
  it "should do something " do
47
46
  controller.json = {'cache_key'=>@cache_key, 'tms_id'=>@tms_id}
48
- controller.should be_valid_bridge_request
47
+ expect(controller.send(:valid_bridge_request?)).to eq(true)
49
48
  end
50
49
 
51
50
  it "should be false if the hash does not match" do
52
51
  controller.json = {'cache_key'=>Digest::SHA2.hexdigest("---#{ENV['CC_BRIDGE_SALT']}--#{@tms_id}--does_not_match--#{IronCacher::CACHE_NAME}--"), 'tms_id'=>@tms_id}
53
- controller.should_not be_valid_bridge_request
52
+ expect(controller.send(:valid_bridge_request?)).to_not eq(true)
54
53
  end
55
54
 
56
55
  it "should be false if the cache value is not found" do
57
56
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
58
- controller.should_not be_valid_bridge_request
57
+ expect(controller.send(:valid_bridge_request?)).to_not eq(true)
59
58
  end
60
59
 
61
60
  it "should be false if json is null" do
62
61
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
63
62
  controller.json = nil
64
- controller.should_not be_valid_bridge_request
63
+ expect(controller.send(:valid_bridge_request?)).to_not eq(true)
65
64
  end
66
65
 
67
66
  it "should be false if no cache_key was passed" do
68
67
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
69
68
  controller.json = {'tms_id'=>@tms_id}
70
- controller.should_not be_valid_bridge_request
71
- end
72
-
73
- end
74
-
75
- describe "parse_iron_mq_json" do
76
- def controller
77
- @controller ||= SecuritiesController.new
78
- end
79
-
80
- it "should set the json attribute and return nil" do
81
- controller.request.raw_post=({tms_id: 17}.to_json)
82
- controller.send(:parse_iron_mq_json).should be_nil
83
- controller.json.class.should eq(Hash)
84
- end
85
-
86
- it "should return false and call head with :ok, if tms_id is not present" do
87
- controller.request.raw_post= nil
88
- controller.should_receive(:head).with(:ok)
89
- controller.send(:parse_iron_mq_json).should == false
90
- end
91
-
92
- end
93
- end
94
-
95
-
96
- describe TmsBridge::ControllerSupport::Redact do
97
- include IronCacher
98
-
99
- class MockRedactionsController<MockController
100
- attr_reader :record, :record_class
101
- extend TmsBridge::ControllerSupport::Redact
102
- redacts_tms :some_client, %w{MockModel}
103
- end
104
-
105
- def controller
106
- @controller ||=MockRedactionsController.new
107
- end
108
-
109
- describe "modules" do
110
- it "should extend security" do
111
- (class << MockRedactionsController; included_modules; end).should include(TmsBridge::ControllerSupport::Security)
112
- end
113
- end
114
-
115
- describe "class_methods" do
116
- it "should assign bridged_resources" do
117
- MockRedactionsController.bridged_resource_names.should == %w{MockModel}
118
- end
119
- end
120
-
121
- describe "instance_methods" do
122
- describe "bridged_resource_class" do
123
-
124
- it "should eval the string and return it if the json attribute record_class is in MockRedactionsController.bridged_resource_names" do
125
- controller.json = {'record_class' => 'MockModel'}
126
- controller.bridged_resource_class.should == MockModel
127
- end
128
-
129
- it "should return nil if the json attribute a record_class is not in MockRedactionsController.bridged_resource_names" do
130
- controller.json = {'record_class' => 'raise'}
131
- controller.bridged_resource_class.should be_nil
132
- end
133
- end
134
- end
135
-
136
- describe "create" do
137
- describe "bridged_resource_class return a class" do
138
- before(:each) do
139
- controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::FOUND}
140
- controller.stub(:bridged_resource_class).and_return(MockModel)
141
- end
142
-
143
- it "should call controller#bridged_resource_class" do
144
- controller.should_receive(:bridged_resource_class)
145
- controller.create
146
- end
147
-
148
- it "should assign to record class" do
149
- controller.create
150
- controller.record_class.should == MockModel
151
- end
152
-
153
- it "should call MockModel.find_by_tms_id" do
154
- MockModel.should_receive(:find_by_tms_id).with(MockModel::FOUND)
155
- controller.create
156
- end
157
-
158
- it "should assign to record if found" do
159
- controller.create
160
- controller.record.should be_is_a(FoundMockPublishing)
161
- end
162
-
163
- it "should call destroy on the found record" do
164
- controller.create
165
- controller.record.called_destroy.should == true
166
- end
167
-
168
- it "should call render" do
169
- controller.should_receive(:render).with(text: 'success')
170
- controller.create
171
- end
172
-
173
- it "should not throw an error if the record is not found" do
174
- controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::NOT_FOUND}
175
- controller.record.should be_nil
176
- controller.should_receive(:render).with(text: 'success')
177
- controller.create
178
- end
179
- end
180
- end
181
- describe "if an invalid record class is passed" do
182
-
183
- before(:each) do
184
- controller.stub(:bridged_resource_class).and_return(nil)
185
- end
186
- it "should call head :ok and" do
187
- controller.should_receive(:head).with(:ok)
188
- controller.create
189
- controller.record.should be_nil
190
- end
191
- end
192
- end
193
-
194
- describe TmsBridge::ControllerSupport::Publish do
195
-
196
- class MockPublishingsController<MockController
197
- attr_reader :mock_publishing
198
-
199
- extend TmsBridge::ControllerSupport::Publish
200
- publishes_tms :some_client
201
- end
202
-
203
- def controller
204
- @controller ||= MockPublishingsController.new
205
- end
206
-
207
- describe "modules" do
208
- it "should extend security" do
209
- (class << MockPublishingsController; included_modules; end).should include(TmsBridge::ControllerSupport::Security)
210
- end
211
-
212
- it "should support update_only?" do
213
- controller.update_only?.should == controller.class.update_only
214
- end
215
-
216
- end
217
-
218
- def widget_controller(params={})
219
- Class.new do
220
- extend TmsBridge::ControllerSupport::Publish
221
- def self.before_filter(*args)
222
- end
223
- def self.name
224
- "WidgetsController"
225
- end
226
- publishes_tms :some_client, params
227
- end
228
-
229
- end
230
-
231
- describe "class_methods" do
232
-
233
- it "should set update_only to false by default" do
234
- widget_controller.update_only.should == false
235
- end
236
-
237
- it "should support manually setting update_only" do
238
- widget_controller(:update_only=>true).update_only.should == true
239
- end
240
-
241
- it "should support setting model_params_key" do
242
- widget_controller(:model_params_key=>'something_else').model_params_key.should == 'something_else'
243
- end
244
-
245
- it "should set model_params_key to bridged_resource by default" do
246
- widget_controller.model_params_key.should == widget_controller.bridged_resource
247
- end
248
-
249
- end
250
-
251
- describe "instance_methods" do
252
-
253
- it "should return the value of class's update_only for update_only?" do
254
- controller = widget_controller
255
- controller.should_receive(:update_only){true}
256
- controller.new.update_only?
257
- end
258
-
259
- it "should return the value of the class's model_params_key" do
260
- controller = widget_controller
261
- controller.should_receive(:model_params_key)
262
- controller.new.model_params_key
263
-
264
- end
265
- end
266
-
267
- describe "create" do
268
- before(:each) do
269
- @attributes = {'some_key'=>'some value'}
270
- @tms_id = MockPublishing::NOT_FOUND
271
- @bridge_id = 'somebridgeid'
272
- controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>@tms_id, 'bridge_id'=>@bridge_id}
273
- end
274
-
275
- it "should assign to the mock_publishing attribute" do
276
- controller.create
277
- controller.mock_publishing.should_not be_nil
278
- end
279
-
280
- it "should assign to attributes" do
281
- controller.create
282
- controller.mock_publishing.attributes.should == @attributes
283
- end
284
-
285
- it "it should call MockPublishing.find_by_tms_id" do
286
- MockPublishing.should_receive(:find_by_tms_id).with(@tms_id)
287
- controller.create
288
- end
289
-
290
- it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nil" do
291
- MockPublishing.should_receive(:new)
292
- controller.create
293
- end
294
-
295
- it "should not pass attributes to the mock model taht are not supported" do
296
- MockPublishing.should_receive(:published_attribute_names){['some_key']}
297
- controller.create
298
- end
299
-
300
- it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing" do
301
- controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
302
- MockPublishing.should_receive(:new)
303
- controller.create
304
- end
305
-
306
- it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing and update_only? == true" do
307
- controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
308
- MockPublishing.should_not_receive(:new)
309
- controller.stub(:update_only?){true}
310
- controller.create
311
- end
312
-
313
- it "should call save on the mock_publishing model" do
314
- controller.create
315
- controller.mock_publishing.called_save.should == true
316
- end
317
-
318
- it "should call render " do
319
- controller.should_receive(:render).with(text: 'success')
320
- controller.create
321
- end
322
-
323
- it "should attempt a lookup of the model with bridge_id if not found by tms_id an supports bridge_id" do
324
- MockPublishing.should_receive(:find_by_tms_id).with(@tms_id){nil}
325
- column_names = MockPublishing.column_names + ['bridge_id']
326
- MockPublishing.stub(:column_names){column_names}
327
- MockPublishing.should_receive(:find_by_bridge_id).with(@bridge_id)
328
- controller.create
329
- end
330
-
331
- it "should attempt a lookup of the model with bridge_id if not found by tms_id an supports bridge_id, but bridge_id is blank" do
332
- MockPublishing.should_receive(:find_by_tms_id).with(@tms_id){nil}
333
- column_names = MockPublishing.column_names + ['bridge_id']
334
- MockPublishing.stub(:column_names){column_names}
335
- MockPublishing.should_not_receive(:find_by_bridge_id).with(@bridge_id)
336
- controller.json['bridge_id'] = nil
337
- controller.create
338
- end
339
-
340
- it "should set the attributes according to model_params_key" do
341
- @attributes = {'some_key'=>'value'}
342
-
343
- controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::FOUND, 'some_model'=>@attributes}
344
- controller.should_receive(:model_params_key).and_return('some_model')
345
- controller.create
346
- controller.mock_publishing.should be_is_a(FoundMockPublishing)
347
- controller.mock_publishing.attributes.should == @attributes
69
+ expect(controller.send(:valid_bridge_request?)).to_not eq(true)
348
70
  end
349
-
350
71
 
351
72
  end
73
+ #
74
+ # describe "parse_iron_mq_json" do
75
+ # def controller
76
+ # @controller ||= SecuritiesController.new
77
+ # end
78
+ #
79
+ # it "should set the json attribute and return nil" do
80
+ # controller.request.raw_post=({tms_id: 17}.to_json)
81
+ # expect(controller.send(:parse_iron_mq_json)).to be_nil
82
+ # expect(controller.json.class).to eq(Hash)
83
+ # end
84
+ #
85
+ # it "should return false and call head with :ok, if tms_id is not present" do
86
+ # controller.request.raw_post= nil
87
+ # expect(controller).to receive(:head).with(:ok)
88
+ # expect(controller.send(:parse_iron_mq_json)).to eq false
89
+ # end
90
+ #
91
+ # end
92
+ # end
93
+ #
94
+ #
95
+ # describe TmsBridge::ControllerSupport::Redact do
96
+ # include IronCacher
97
+ #
98
+ # class MockRedactionsController<MockController
99
+ # attr_reader :record, :record_class
100
+ # extend TmsBridge::ControllerSupport::Redact
101
+ # redacts_tms :some_client, %w{MockModel}
102
+ # end
103
+ #
104
+ # def controller
105
+ # @controller ||=MockRedactionsController.new
106
+ # end
107
+ #
108
+ # describe "modules" do
109
+ # it "should extend security" do
110
+ # expect((class << MockRedactionsController; included_modules; end)).to include(TmsBridge::ControllerSupport::Security)
111
+ # end
112
+ # end
113
+ #
114
+ # describe "class_methods" do
115
+ # it "should assign bridged_resources" do
116
+ # expect(MockRedactionsController.bridged_resource_names).to eq %w{MockModel}
117
+ # end
118
+ # end
119
+ #
120
+ # describe "instance_methods" do
121
+ # describe "bridged_resource_class" do
122
+ #
123
+ # it "should eval the string and return it if the json attribute record_class is in MockRedactionsController.bridged_resource_names" do
124
+ # controller.json = {'record_class' => 'MockModel'}
125
+ # expect(controller.bridged_resource_class).to eq MockModel
126
+ # end
127
+ #
128
+ # it "should return nil if the json attribute a record_class is not in MockRedactionsController.bridged_resource_names" do
129
+ # controller.json = {'record_class' => 'raise'}
130
+ # expect(controller.bridged_resource_class).to be_nil
131
+ # end
132
+ # end
133
+ # end
134
+ #
135
+ # describe "create" do
136
+ # describe "bridged_resource_class return a class" do
137
+ # before(:each) do
138
+ # controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::FOUND}
139
+ # controller.stub(:bridged_resource_class).and_return(MockModel)
140
+ # end
141
+ #
142
+ # it "should call controller#bridged_resource_class" do
143
+ # expect(controller).to receive(:bridged_resource_class)
144
+ # controller.create
145
+ # end
146
+ #
147
+ # it "should assign to record class" do
148
+ # controller.create
149
+ # expect(controller.record_class).to eq MockModel
150
+ # end
151
+ #
152
+ # it "should call MockModel.find_by_tms_id" do
153
+ # expect(MockModel).to receive(:find_by_tms_id).with(MockModel::FOUND)
154
+ # controller.create
155
+ # end
156
+ #
157
+ # it "should assign to record if found" do
158
+ # controller.create
159
+ # expect(controller.record).to be_a(FoundMockPublishing)
160
+ # end
161
+ #
162
+ # it "should call destroy on the found record" do
163
+ # controller.create
164
+ # expect(controller.record.called_destroy).to eq true
165
+ # end
166
+ #
167
+ # it "should call render" do
168
+ # expect(controller).to receive(:render).with(text: 'success')
169
+ # controller.create
170
+ # end
171
+ #
172
+ # it "should not throw an error if the record is not found" do
173
+ # controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::NOT_FOUND}
174
+ # expect(controller.record).to be_nil
175
+ # expect(controller).to receive(:render).with(text: 'success')
176
+ # controller.create
177
+ # end
178
+ # end
179
+ # end
180
+ # describe "if an invalid record class is passed" do
181
+ #
182
+ # before(:each) do
183
+ # controller.stub(:bridged_resource_class).and_return(nil)
184
+ # end
185
+ # it "should call head :ok and" do
186
+ # expect(controller).to receive(:head).with(:ok)
187
+ # controller.create
188
+ # expect(controller.record).to be_nil
189
+ # end
190
+ # end
191
+ # end
192
+ #
193
+ # describe TmsBridge::ControllerSupport::Publish do
194
+ #
195
+ # class MockPublishingsController<MockController
196
+ # attr_reader :mock_publishing
197
+ #
198
+ # extend TmsBridge::ControllerSupport::Publish
199
+ # publishes_tms :some_client
200
+ # end
201
+ #
202
+ # def controller
203
+ # @controller ||= MockPublishingsController.new
204
+ # end
205
+ #
206
+ # describe "modules" do
207
+ # it "should extend security" do
208
+ # expect((class << MockPublishingsController; included_modules; end)).to include(TmsBridge::ControllerSupport::Security)
209
+ # end
210
+ #
211
+ # it "should support update_only?" do
212
+ # expect(controller.update_only?).to eq controller.class.update_only
213
+ # end
214
+ #
215
+ # end
216
+ #
217
+ # def widget_controller(params={})
218
+ # Class.new do
219
+ # extend TmsBridge::ControllerSupport::Publish
220
+ # def self.before_filter(*args)
221
+ # end
222
+ # def self.name
223
+ # "WidgetsController"
224
+ # end
225
+ # publishes_tms :some_client, params
226
+ # end
227
+ #
228
+ # end
229
+ #
230
+ # describe "class_methods" do
231
+ #
232
+ # it "should set update_only to false by default" do
233
+ # expect(widget_controller.update_only).to eq false
234
+ # end
235
+ #
236
+ # it "should support manually setting update_only" do
237
+ # expect(widget_controller(:update_only=>true).update_only).to eq true
238
+ # end
239
+ #
240
+ # it "should support setting model_params_key" do
241
+ # expect(widget_controller(:model_params_key=>'something_else').model_params_key).to eq 'something_else'
242
+ # end
243
+ #
244
+ # it "should set model_params_key to bridged_resource by default" do
245
+ # expect(widget_controller.model_params_key).to eq widget_controller.bridged_resource
246
+ # end
247
+ #
248
+ # end
249
+ #
250
+ # describe "instance_methods" do
251
+ #
252
+ # it "should return the value of class's update_only for update_only?" do
253
+ # controller = widget_controller
254
+ # expect(controller).to receive(:update_only){true}
255
+ # controller.new.update_only?
256
+ # end
257
+ #
258
+ # it "should return the value of the class's model_params_key" do
259
+ # controller = widget_controller
260
+ # expect(controller).to receive(:model_params_key)
261
+ # controller.new.model_params_key
262
+ #
263
+ # end
264
+ # end
265
+ #
266
+ # describe "create" do
267
+ # before(:each) do
268
+ # @attributes = {'some_key'=>'some value'}
269
+ # @tms_id = MockPublishing::NOT_FOUND
270
+ # @bridge_id = 'somebridgeid'
271
+ # controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>@tms_id, 'bridge_id'=>@bridge_id}
272
+ # end
273
+ #
274
+ # it "should assign to the mock_publishing attribute" do
275
+ # controller.create
276
+ # expect(controller.mock_publishing).to_not be_nil
277
+ # end
278
+ #
279
+ # it "should assign to attributes" do
280
+ # controller.create
281
+ # expect(controller.mock_publishing.attributes).to eq @attributes
282
+ # end
283
+ #
284
+ # it "it should call MockPublishing.find_by_tms_id" do
285
+ # expect(MockPublishing).to receive(:find_by_tms_id).with(@tms_id)
286
+ # controller.create
287
+ # end
288
+ #
289
+ # it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nil" do
290
+ # expect(MockPublishing).to receive(:new)
291
+ # controller.create
292
+ # end
293
+ #
294
+ # it "should not pass attributes to the mock model taht are not supported" do
295
+ # expect(MockPublishing).to receive(:published_attribute_names){['some_key']}
296
+ # controller.create
297
+ # end
298
+ #
299
+ # it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing" do
300
+ # controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
301
+ # expect(MockPublishing).to receive(:new)
302
+ # controller.create
303
+ # end
304
+ #
305
+ # it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing and update_only? == true" do
306
+ # controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
307
+ # expect(MockPublishing).to_not receive(:new)
308
+ # controller.stub(:update_only?){true}
309
+ # controller.create
310
+ # end
311
+ #
312
+ # it "should call save on the mock_publishing model" do
313
+ # controller.create
314
+ # expect(controller.mock_publishing.called_save).to eq true
315
+ # end
316
+ #
317
+ # it "should call render " do
318
+ # expect(controller).to receive(:render).with(text: 'success')
319
+ # controller.create
320
+ # end
321
+ #
322
+ # it "should attempt a lookup of the model with bridge_id if not found by tms_id an supports bridge_id" do
323
+ # expect(MockPublishing).to receive(:find_by_tms_id).with(@tms_id){nil}
324
+ # column_names = MockPublishing.column_names + ['bridge_id']
325
+ # MockPublishing.stub(:column_names){column_names}
326
+ # expect(MockPublishing).to receive(:find_by_bridge_id).with(@bridge_id)
327
+ # controller.create
328
+ # end
329
+ #
330
+ # it "should attempt a lookup of the model with bridge_id if not found by tms_id an supports bridge_id, but bridge_id is blank" do
331
+ # expect(MockPublishing).to receive(:find_by_tms_id).with(@tms_id){nil}
332
+ # column_names = MockPublishing.column_names + ['bridge_id']
333
+ # MockPublishing.stub(:column_names){column_names}
334
+ # expect(MockPublishing).to_not receive(:find_by_bridge_id).with(@bridge_id)
335
+ # controller.json['bridge_id'] = nil
336
+ # controller.create
337
+ # end
338
+ #
339
+ # it "should set the attributes according to model_params_key" do
340
+ # @attributes = {'some_key'=>'value'}
341
+ #
342
+ # controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::FOUND, 'some_model'=>@attributes}
343
+ # expect(controller).to receive(:model_params_key).and_return('some_model')
344
+ # controller.create
345
+ # expect(controller.mock_publishing).to be_a(FoundMockPublishing)
346
+ # expect(controller.mock_publishing.attributes).to eq @attributes
347
+ # end
348
+ #
349
+ #
350
+ # end
352
351
  end
@@ -8,6 +8,10 @@ class MockModel
8
8
  def self.column_names
9
9
  ['updated_at', 'created_at', 'id', 'some_key']
10
10
  end
11
+
12
+ def self.attribute_aliases
13
+ return {}
14
+ end
11
15
 
12
16
  def save(*args)
13
17
  self.called_save = true
@@ -5,19 +5,24 @@ require File.expand_path(File.dirname(__FILE__) + '/mocks')
5
5
  describe TmsBridge::ModelSupport do
6
6
  describe "published_attributes" do
7
7
  it "should not include 'id'" do
8
- MockModel.published_attribute_names.should_not include('id')
8
+ expect(MockModel.published_attribute_names).to_not include('id')
9
9
  end
10
-
10
+
11
11
  it "should not include 'created_at'" do
12
- MockModel.published_attribute_names.should_not include('created_at')
12
+ expect(MockModel.published_attribute_names).to_not include('created_at')
13
13
  end
14
-
14
+
15
15
  it "should not include 'updated_at" do
16
- MockModel.published_attribute_names.should_not include('updated_at')
16
+ expect(MockModel.published_attribute_names).to_not include('updated_at')
17
17
  end
18
-
18
+
19
19
  it "should include items declared in column_names" do
20
- MockModel.published_attribute_names.should include('some_key')
20
+ expect(MockModel.published_attribute_names).to include('some_key')
21
+ end
22
+
23
+ it "should include alias_attributes" do
24
+ expect(MockModel).to receive(:attribute_aliases){{"alias_key"=>"some_key"}}
25
+ expect(MockModel.published_attribute_names).to include('alias_key')
21
26
  end
22
27
  end
23
28
  end
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec", "~> 2.6"
23
+ spec.add_development_dependency "rspec", "~> 3"
24
24
  spec.add_dependency "actionpack", ">= 3.2.0"
25
25
  spec.add_dependency "activerecord", ">= 3.2.0"
26
26
  spec.add_dependency "uuidtools"
metadata CHANGED
@@ -1,128 +1,128 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tms_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Timkar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-05 00:00:00.000000000 Z
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.6'
47
+ version: '3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.6'
54
+ version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: actionpack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.2.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.2.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 3.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 3.2.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: uuidtools
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ! '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ! '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: iron_cache
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ! '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: typhoeus
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ! '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- description: ! 'Provides parsing and authtentication for publishing into TMS client
125
+ description: 'Provides parsing and authtentication for publishing into TMS client
126
126
  apps. '
127
127
  email:
128
128
  - erich@teamdriveaway.com
@@ -130,9 +130,9 @@ executables: []
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - .gitignore
134
- - .ruby-gemset
135
- - .ruby-version
133
+ - ".gitignore"
134
+ - ".ruby-gemset"
135
+ - ".ruby-version"
136
136
  - Gemfile
137
137
  - Gemfile.lock
138
138
  - LICENSE.txt
@@ -158,17 +158,17 @@ require_paths:
158
158
  - lib
159
159
  required_ruby_version: !ruby/object:Gem::Requirement
160
160
  requirements:
161
- - - ! '>='
161
+ - - ">="
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  requirements:
166
- - - ! '>='
166
+ - - ">="
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.4.2
171
+ rubygems_version: 2.4.8
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: ''