tms_bridge 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGM4YzdjNmQ4MmMyZTNiN2Q5YTZjOTNkMGEzNDk2ZjI4YTMwZGM5OA==
4
+ MTAzYWNhZDAzOGU1MDMwYWZiNTk1NTZmOTg1Yzg0MGM5MDYyZGQ2Nw==
5
5
  data.tar.gz: !binary |-
6
- NjA5ZWEwOTZmMDQ3MDg0MDM5OTg2M2E2MTc4ZGI1M2U2NGZlZWI5OQ==
6
+ ZTY1YzI1YWE1ZGJlMzg4NjI0NGQ3ZTMxNjJkYmUxMDAyNjgyMzAxMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmM2MDRmMjM4MzQ0MTQzNWY0ZWM1YzIxNjE1ZjQ1YjMzYWQxODA2ZDkyNTE2
10
- ZTdjYzc2MDhjNWNkYjU1YmMwMzA3NjA3YTljMzY4NzVkODg1YTFkYTQzZmRm
11
- YzIzNDY1Y2EyZGViYTdiZjYyYTc4Nzc3N2EzMGQyZGVkZjE2ZTA=
9
+ YzU1NDE0NTFiZmUxNjkzZjQwOWU3MWNhMWQ5MDk2YmUyNjc3MGJkNTlkOTg1
10
+ N2FhNDUzZDFkODU5MDUxNWE5ZmQyNWI5MThlY2Y0Y2Q2MGI1OGZiMWEyYjIx
11
+ MmEyNDFhMzNjOWU0Yjg5MGZiMDJkODUwYjYzNWY1MzkwZTgwMjg=
12
12
  data.tar.gz: !binary |-
13
- NWQzNWNmY2U4MjY0NzY3ZTIwNmNmMmNiYTZjY2NlMzY5ZmVjZmU0Y2VlM2Vi
14
- NWUxZmUyZTRkMjI2NzIyNGQyZTk2M2MzMjY0M2QzNTNiOGY2Yzg2NTIwMDMx
15
- ZjNmNDY1MTk0MDhjMDBjODNhYzhmMGFiZGZmMDQ5ODIxYWQwZGM=
13
+ OGQwYWFiMjlmNTQ4ZGU4OTM1ODdhZWUwOGJjM2RkODZhZjA5YWYxMTBiMTBj
14
+ ZDZiMGM5ZDIzN2RhZjk2M2Y3NjQ5YzI3M2JlODA1ZDU2YzAyNmU4NmJlYTZk
15
+ OGE2NGMwNzkyNWE0NWQ0OTA0Njg2MTk1YzdhYTEyNzlkNDgzNjk=
@@ -0,0 +1 @@
1
+ tms.bridge
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p545
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tms_bridge (0.1.1)
4
+ tms_bridge (0.1.2)
5
5
  actionpack (>= 3.2.0)
6
6
  activerecord (>= 3.2.0)
7
7
  iron_cache
@@ -42,15 +42,20 @@ RUBY
42
42
  end
43
43
 
44
44
  module Publish
45
- def publishes_tms(as, options={:update_only=>false})
45
+ def publishes_tms(as, options={})
46
46
  extend TmsBridge::ControllerSupport::Security unless (class << self; included_modules; end).include?(TmsBridge::ControllerSupport::Security)
47
47
  extend TmsBridge::ControllerSupport::Publish::ClassMethods unless (class << self; included_modules; end).include?(TmsBridge::ControllerSupport::Publish::ClassMethods)
48
48
  include TmsBridge::ControllerSupport::Publish::InstanceMethods unless included_modules.include?(TmsBridge::ControllerSupport::Publish::InstanceMethods)
49
49
 
50
50
  self.secure_tms_bridge(as)
51
- class_name = self.bridged_resources.classify
52
51
 
52
+ class_name = self.bridged_resources.classify
53
+
54
+ options= options.reverse_merge({:update_only=>false, :model_params_key=>self.bridged_resource})
55
+
53
56
  self.update_only = options[:update_only]
57
+ self.model_params_key = options[:model_params_key]
58
+
54
59
  class_eval <<-RUBY, __FILE__, __LINE__+1
55
60
  def create
56
61
  @#{self.bridged_resource} = #{class_name}.find_by_tms_id(@json['tms_id'])
@@ -60,8 +65,9 @@ RUBY
60
65
  end
61
66
 
62
67
  @#{self.bridged_resource} = #{class_name}.new if @#{self.bridged_resource}.nil? && !self.update_only?
68
+
63
69
  if @#{self.bridged_resource}
64
- @#{self.bridged_resource}.attributes = @json['#{self.bridged_resource}'].slice(*#{class_name}.published_attribute_names)
70
+ @#{self.bridged_resource}.attributes = @json[self.model_params_key.to_s].slice(*#{class_name}.published_attribute_names)
65
71
  @#{self.bridged_resource}.save(validate: false)
66
72
  end
67
73
  render text: 'success'
@@ -74,6 +80,8 @@ RUBY
74
80
  module ClassMethods
75
81
  def self.extended(base)
76
82
  base.class_attribute :update_only
83
+ base.class_attribute(:model_params_key)
84
+
77
85
  end
78
86
  end
79
87
 
@@ -81,6 +89,8 @@ RUBY
81
89
  def update_only?
82
90
  self.class.update_only
83
91
  end
92
+
93
+
84
94
  end
85
95
 
86
96
  end
@@ -91,6 +101,7 @@ RUBY
91
101
  include TmsBridge::ControllerSupport::Security::InstanceMethods
92
102
  extend TmsBridge::ControllerSupport::Security::ClassMethods
93
103
  self.as = as.to_s
104
+
94
105
  self.bridged_resources = self.name.split('::').last.gsub(/Controller/, '').underscore
95
106
  self.bridged_resource = self.bridged_resources.singularize
96
107
  self.queue_name = self.as + '_'+self.bridged_resources
@@ -1,3 +1,3 @@
1
1
  module Bridge
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -12,7 +12,7 @@ describe IronCacher do
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 == ENV['IRON_CACHE_PROJECT_ID']
15
+ MockIronCache.iron_cache_client.project_id.should == JSON.parse(File.read("config/iron.json"))['project_id']
16
16
  end
17
17
 
18
18
  end
@@ -9,7 +9,7 @@ describe TmsBridge::ControllerSupport::Security do
9
9
  extend TmsBridge::ControllerSupport::Security
10
10
  secure_tms_bridge :some_client
11
11
  end
12
-
12
+
13
13
  describe "class attributes" do
14
14
  it "should define and set 'as' " do
15
15
  SecuritiesController.as.should == 'some_client'
@@ -26,7 +26,7 @@ describe TmsBridge::ControllerSupport::Security do
26
26
  it "should define and set 'queue_name' " do
27
27
  SecuritiesController.queue_name.should == 'some_client_securities'
28
28
  end
29
-
29
+
30
30
  it "should add :parse_iron_mq_json to the before_filters" do
31
31
  SecuritiesController.before_filters.should include(:parse_iron_mq_json)
32
32
  end
@@ -42,36 +42,36 @@ describe TmsBridge::ControllerSupport::Security do
42
42
  def controller
43
43
  @controller ||= SecuritiesController.new
44
44
  end
45
-
45
+
46
46
  it "should do something " do
47
- controller.json = {'cache_key'=>@cache_key, 'tms_id'=>@tms_id}
47
+ controller.json = {'cache_key'=>@cache_key, 'tms_id'=>@tms_id}
48
48
  controller.should be_valid_bridge_request
49
49
  end
50
-
50
+
51
51
  it "should be false if the hash does not match" do
52
- controller.json = {'cache_key'=>Digest::SHA2.hexdigest("---#{ENV['CC_BRIDGE_SALT']}--#{@tms_id}--does_not_match--#{IronCacher::CACHE_NAME}--"), 'tms_id'=>@tms_id}
52
+ controller.json = {'cache_key'=>Digest::SHA2.hexdigest("---#{ENV['CC_BRIDGE_SALT']}--#{@tms_id}--does_not_match--#{IronCacher::CACHE_NAME}--"), 'tms_id'=>@tms_id}
53
53
  controller.should_not be_valid_bridge_request
54
54
  end
55
-
55
+
56
56
  it "should be false if the cache value is not found" do
57
57
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
58
58
  controller.should_not be_valid_bridge_request
59
59
  end
60
-
60
+
61
61
  it "should be false if json is null" do
62
62
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
63
63
  controller.json = nil
64
64
  controller.should_not be_valid_bridge_request
65
65
  end
66
-
66
+
67
67
  it "should be false if no cache_key was passed" do
68
68
  iron_cache(IronCacher::CACHE_NAME).delete(@cache_key)
69
- controller.json = {'tms_id'=>@tms_id}
69
+ controller.json = {'tms_id'=>@tms_id}
70
70
  controller.should_not be_valid_bridge_request
71
71
  end
72
-
72
+
73
73
  end
74
-
74
+
75
75
  describe "parse_iron_mq_json" do
76
76
  def controller
77
77
  @controller ||= SecuritiesController.new
@@ -82,69 +82,69 @@ describe TmsBridge::ControllerSupport::Security do
82
82
  controller.send(:parse_iron_mq_json).should be_nil
83
83
  controller.json.class.should eq(Hash)
84
84
  end
85
-
85
+
86
86
  it "should return false and call head with :ok, if tms_id is not present" do
87
87
  controller.request.raw_post= nil
88
88
  controller.should_receive(:head).with(:ok)
89
89
  controller.send(:parse_iron_mq_json).should == false
90
90
  end
91
-
91
+
92
92
  end
93
93
  end
94
94
 
95
95
 
96
96
  describe TmsBridge::ControllerSupport::Redact do
97
97
  include IronCacher
98
-
98
+
99
99
  class MockRedactionsController<MockController
100
100
  attr_reader :record, :record_class
101
101
  extend TmsBridge::ControllerSupport::Redact
102
102
  redacts_tms :some_client, %w{MockModel}
103
103
  end
104
-
104
+
105
105
  def controller
106
106
  @controller ||=MockRedactionsController.new
107
107
  end
108
-
108
+
109
109
  describe "modules" do
110
110
  it "should extend security" do
111
111
  (class << MockRedactionsController; included_modules; end).should include(TmsBridge::ControllerSupport::Security)
112
112
  end
113
113
  end
114
-
114
+
115
115
  describe "class_methods" do
116
116
  it "should assign bridged_resources" do
117
117
  MockRedactionsController.bridged_resource_names.should == %w{MockModel}
118
118
  end
119
119
  end
120
-
120
+
121
121
  describe "instance_methods" do
122
122
  describe "bridged_resource_class" do
123
-
123
+
124
124
  it "should eval the string and return it if the json attribute record_class is in MockRedactionsController.bridged_resource_names" do
125
125
  controller.json = {'record_class' => 'MockModel'}
126
126
  controller.bridged_resource_class.should == MockModel
127
127
  end
128
-
128
+
129
129
  it "should return nil if the json attribute a record_class is not in MockRedactionsController.bridged_resource_names" do
130
130
  controller.json = {'record_class' => 'raise'}
131
131
  controller.bridged_resource_class.should be_nil
132
132
  end
133
133
  end
134
134
  end
135
-
135
+
136
136
  describe "create" do
137
137
  describe "bridged_resource_class return a class" do
138
138
  before(:each) do
139
139
  controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::FOUND}
140
140
  controller.stub(:bridged_resource_class).and_return(MockModel)
141
141
  end
142
-
142
+
143
143
  it "should call controller#bridged_resource_class" do
144
144
  controller.should_receive(:bridged_resource_class)
145
145
  controller.create
146
146
  end
147
-
147
+
148
148
  it "should assign to record class" do
149
149
  controller.create
150
150
  controller.record_class.should == MockModel
@@ -154,21 +154,22 @@ describe TmsBridge::ControllerSupport::Redact do
154
154
  MockModel.should_receive(:find_by_tms_id).with(MockModel::FOUND)
155
155
  controller.create
156
156
  end
157
-
157
+
158
158
  it "should assign to record if found" do
159
159
  controller.create
160
160
  controller.record.should be_is_a(FoundMockPublishing)
161
161
  end
162
-
162
+
163
163
  it "should call destroy on the found record" do
164
164
  controller.create
165
165
  controller.record.called_destroy.should == true
166
166
  end
167
-
167
+
168
168
  it "should call render" do
169
169
  controller.should_receive(:render).with(text: 'success')
170
170
  controller.create
171
171
  end
172
+
172
173
  it "should not throw an error if the record is not found" do
173
174
  controller.json={'record_class'=>'MockModel', 'tms_id'=>MockModel::NOT_FOUND}
174
175
  controller.record.should be_nil
@@ -191,7 +192,7 @@ describe TmsBridge::ControllerSupport::Redact do
191
192
  end
192
193
 
193
194
  describe TmsBridge::ControllerSupport::Publish do
194
-
195
+
195
196
  class MockPublishingsController<MockController
196
197
  attr_reader :mock_publishing
197
198
 
@@ -207,12 +208,62 @@ describe TmsBridge::ControllerSupport::Publish do
207
208
  it "should extend security" do
208
209
  (class << MockPublishingsController; included_modules; end).should include(TmsBridge::ControllerSupport::Security)
209
210
  end
210
-
211
+
211
212
  it "should support update_only?" do
212
213
  controller.update_only?.should == controller.class.update_only
213
214
  end
215
+
214
216
  end
215
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
+
216
267
  describe "create" do
217
268
  before(:each) do
218
269
  @attributes = {'some_key'=>'some value'}
@@ -220,17 +271,17 @@ describe TmsBridge::ControllerSupport::Publish do
220
271
  @bridge_id = 'somebridgeid'
221
272
  controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>@tms_id, 'bridge_id'=>@bridge_id}
222
273
  end
223
-
274
+
224
275
  it "should assign to the mock_publishing attribute" do
225
276
  controller.create
226
277
  controller.mock_publishing.should_not be_nil
227
278
  end
228
-
279
+
229
280
  it "should assign to attributes" do
230
281
  controller.create
231
282
  controller.mock_publishing.attributes.should == @attributes
232
283
  end
233
-
284
+
234
285
  it "it should call MockPublishing.find_by_tms_id" do
235
286
  MockPublishing.should_receive(:find_by_tms_id).with(@tms_id)
236
287
  controller.create
@@ -240,41 +291,41 @@ describe TmsBridge::ControllerSupport::Publish do
240
291
  MockPublishing.should_receive(:new)
241
292
  controller.create
242
293
  end
243
-
294
+
244
295
  it "should not pass attributes to the mock model taht are not supported" do
245
296
  MockPublishing.should_receive(:published_attribute_names){['some_key']}
246
297
  controller.create
247
298
  end
248
-
299
+
249
300
  it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing" do
250
- controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
301
+ controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
251
302
  MockPublishing.should_receive(:new)
252
303
  controller.create
253
304
  end
254
-
305
+
255
306
  it "it should call MockPublishing.new if MockPublishing.find_by_tms_id returns nothing and update_only? == true" do
256
- controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
307
+ controller.json = {'mock_publishing'=>@attributes, 'tms_id'=>MockPublishing::NOT_FOUND}
257
308
  MockPublishing.should_not_receive(:new)
258
309
  controller.stub(:update_only?){true}
259
310
  controller.create
260
311
  end
261
-
312
+
262
313
  it "should call save on the mock_publishing model" do
263
314
  controller.create
264
315
  controller.mock_publishing.called_save.should == true
265
316
  end
266
-
317
+
267
318
  it "should call render " do
268
319
  controller.should_receive(:render).with(text: 'success')
269
320
  controller.create
270
321
  end
271
-
322
+
272
323
  it "should attempt a lookup of the model with bridge_id if not found by tms_id an supports bridge_id" do
273
324
  MockPublishing.should_receive(:find_by_tms_id).with(@tms_id){nil}
274
325
  column_names = MockPublishing.column_names + ['bridge_id']
275
326
  MockPublishing.stub(:column_names){column_names}
276
327
  MockPublishing.should_receive(:find_by_bridge_id).with(@bridge_id)
277
- controller.create
328
+ controller.create
278
329
  end
279
330
 
280
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
@@ -283,8 +334,19 @@ describe TmsBridge::ControllerSupport::Publish do
283
334
  MockPublishing.stub(:column_names){column_names}
284
335
  MockPublishing.should_not_receive(:find_by_bridge_id).with(@bridge_id)
285
336
  controller.json['bridge_id'] = nil
286
- controller.create
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
287
348
  end
288
349
 
350
+
289
351
  end
290
352
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tms_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erich Timkar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,7 +131,8 @@ extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
133
  - .gitignore
134
- - .rvmrc
134
+ - .ruby-gemset
135
+ - .ruby-version
135
136
  - Gemfile
136
137
  - Gemfile.lock
137
138
  - LICENSE.txt
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  requirements: []
169
170
  rubyforge_project:
170
- rubygems_version: 2.1.9
171
+ rubygems_version: 2.4.2
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: ''
data/.rvmrc DELETED
@@ -1,7 +0,0 @@
1
- export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
2
- export RUBYOPT=-Ku
3
- export IRON_CACHE_TOKEN="6P0Hr8umXZruKzS3SbKF1vuu1E8"
4
- export IRON_CACHE_PROJECT_ID="50a79df0a6498073e700560c"
5
- export CC_BRIDGE_SALT="c7b5fae1-d719-4c8e-b92b-1c4c5e26ca10"
6
-
7
- rvm --create use 1.9.3@tms.bridge > /dev/null