test_track_rails_client 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -7
- data/Rakefile +8 -4
- data/app/models/test_track/analytics/mixpanel_client.rb +2 -5
- data/app/models/test_track/analytics/safe_wrapper.rb +4 -4
- data/app/models/test_track/config_updater.rb +2 -2
- data/app/models/test_track/fake/split_registry.rb +2 -2
- data/app/models/test_track/notify_assignment_job.rb +3 -4
- data/app/models/test_track/offline_session.rb +6 -4
- data/app/models/test_track/remote/split_registry.rb +2 -2
- data/app/models/test_track/remote/visitor.rb +2 -2
- data/app/models/test_track/session.rb +12 -73
- data/app/models/test_track/unsynced_assignments_notifier.rb +2 -4
- data/app/models/test_track/vary_dsl.rb +5 -1
- data/app/models/test_track/visitor.rb +0 -11
- data/lib/test_track_rails_client/version.rb +1 -1
- data/vendor/gems/fakeable_her/fakeable_her.gemspec +2 -3
- data/vendor/gems/her/her.gemspec +4 -5
- data/vendor/gems/her/lib/her/api.rb +1 -1
- data/vendor/gems/her/lib/her/model/associations/association_proxy.rb +1 -2
- data/vendor/gems/her/lib/her/model/orm.rb +41 -29
- data/vendor/gems/her/lib/her/model/parse.rb +1 -0
- data/vendor/gems/her/lib/her/model/relation.rb +21 -6
- data/vendor/gems/her/lib/her/version.rb +1 -1
- metadata +52 -139
- data/app/models/test_track/create_alias_job.rb +0 -18
- data/vendor/gems/her/CONTRIBUTING.md +0 -26
- data/vendor/gems/her/Gemfile +0 -10
- data/vendor/gems/her/README.md +0 -1023
- data/vendor/gems/her/Rakefile +0 -11
- data/vendor/gems/her/UPGRADE.md +0 -101
- data/vendor/gems/her/gemfiles/Gemfile.activemodel-3.2.x +0 -7
- data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.0 +0 -7
- data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.1 +0 -7
- data/vendor/gems/her/gemfiles/Gemfile.activemodel-4.2 +0 -7
- data/vendor/gems/her/spec/api_spec.rb +0 -114
- data/vendor/gems/her/spec/collection_spec.rb +0 -26
- data/vendor/gems/her/spec/error_collection_spec.rb +0 -33
- data/vendor/gems/her/spec/json_api/model_spec.rb +0 -168
- data/vendor/gems/her/spec/middleware/accept_json_spec.rb +0 -10
- data/vendor/gems/her/spec/middleware/first_level_parse_json_spec.rb +0 -62
- data/vendor/gems/her/spec/middleware/json_api_parser_spec.rb +0 -32
- data/vendor/gems/her/spec/middleware/second_level_parse_json_spec.rb +0 -35
- data/vendor/gems/her/spec/model/associations/association_proxy_spec.rb +0 -31
- data/vendor/gems/her/spec/model/associations_spec.rb +0 -504
- data/vendor/gems/her/spec/model/attributes_spec.rb +0 -404
- data/vendor/gems/her/spec/model/callbacks_spec.rb +0 -145
- data/vendor/gems/her/spec/model/dirty_spec.rb +0 -110
- data/vendor/gems/her/spec/model/http_spec.rb +0 -165
- data/vendor/gems/her/spec/model/introspection_spec.rb +0 -76
- data/vendor/gems/her/spec/model/nested_attributes_spec.rb +0 -134
- data/vendor/gems/her/spec/model/orm_spec.rb +0 -791
- data/vendor/gems/her/spec/model/parse_spec.rb +0 -372
- data/vendor/gems/her/spec/model/paths_spec.rb +0 -347
- data/vendor/gems/her/spec/model/relation_spec.rb +0 -226
- data/vendor/gems/her/spec/model/validations_spec.rb +0 -42
- data/vendor/gems/her/spec/model_spec.rb +0 -31
- data/vendor/gems/her/spec/spec_helper.rb +0 -27
- data/vendor/gems/her/spec/support/extensions/array.rb +0 -5
- data/vendor/gems/her/spec/support/extensions/hash.rb +0 -5
- data/vendor/gems/her/spec/support/macros/her_macros.rb +0 -17
- data/vendor/gems/her/spec/support/macros/model_macros.rb +0 -36
- data/vendor/gems/her/spec/support/macros/request_macros.rb +0 -27
- data/vendor/gems/publicsuffix-ruby/CHANGELOG.md +0 -236
- data/vendor/gems/publicsuffix-ruby/Gemfile +0 -3
- data/vendor/gems/publicsuffix-ruby/LICENSE.txt +0 -22
- data/vendor/gems/publicsuffix-ruby/README.md +0 -151
- data/vendor/gems/publicsuffix-ruby/Rakefile +0 -109
- data/vendor/gems/publicsuffix-ruby/lib/definitions.txt +0 -11467
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix/domain.rb +0 -387
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix/errors.rb +0 -53
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix/list.rb +0 -302
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix/rule.rb +0 -373
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix/version.rb +0 -23
- data/vendor/gems/publicsuffix-ruby/lib/public_suffix.rb +0 -131
- data/vendor/gems/publicsuffix-ruby/public_suffix.gemspec +0 -39
- data/vendor/gems/publicsuffix-ruby/test/acceptance_test.rb +0 -42
- data/vendor/gems/publicsuffix-ruby/test/test_helper.rb +0 -6
- data/vendor/gems/publicsuffix-ruby/test/unit/domain_test.rb +0 -170
- data/vendor/gems/publicsuffix-ruby/test/unit/errors_test.rb +0 -23
- data/vendor/gems/publicsuffix-ruby/test/unit/list_test.rb +0 -179
- data/vendor/gems/publicsuffix-ruby/test/unit/public_suffix_test.rb +0 -115
- data/vendor/gems/publicsuffix-ruby/test/unit/rule_test.rb +0 -307
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/capybara_configuration.rb +0 -98
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/matchers.rb +0 -151
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rspec_configuration.rb +0 -34
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/html_safe.rb +0 -15
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/raw.rb +0 -15
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop/cop/betterment/safe_concat.rb +0 -15
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/rubocop.rb +0 -3
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples/betterment_application_examples.rb +0 -43
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/shared_examples.rb +0 -1
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_configuration.rb +0 -42
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/site_prism_dropdown.rb +0 -17
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/version.rb +0 -3
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers/webmock_configuration.rb +0 -8
- data/vendor/gems/ruby_spec_helpers/lib/ruby_spec_helpers.rb +0 -2
- data/vendor/gems/ruby_spec_helpers/ruby_spec_helpers.gemspec +0 -25
@@ -1,404 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
3
|
-
require 'yaml'
|
4
|
-
|
5
|
-
describe Her::Model::Attributes do
|
6
|
-
context "mapping data to Ruby objects" do
|
7
|
-
before { spawn_model "Foo::User" }
|
8
|
-
|
9
|
-
it "handles new resource" do
|
10
|
-
@new_user = Foo::User.new(:fullname => "Tobias Fünke")
|
11
|
-
@new_user.new?.should be_truthy
|
12
|
-
@new_user.fullname.should == "Tobias Fünke"
|
13
|
-
end
|
14
|
-
|
15
|
-
it "accepts new resource with strings as hash keys" do
|
16
|
-
@new_user = Foo::User.new('fullname' => "Tobias Fünke")
|
17
|
-
@new_user.fullname.should == "Tobias Fünke"
|
18
|
-
end
|
19
|
-
|
20
|
-
it "handles method missing for getter" do
|
21
|
-
@new_user = Foo::User.new(:fullname => 'Mayonegg')
|
22
|
-
expect { @new_user.unknown_method_for_a_user }.to raise_error(NoMethodError)
|
23
|
-
expect { @new_user.fullname }.not_to raise_error()
|
24
|
-
end
|
25
|
-
|
26
|
-
it "handles method missing for setter" do
|
27
|
-
@new_user = Foo::User.new
|
28
|
-
expect { @new_user.fullname = "Tobias Fünke" }.not_to raise_error()
|
29
|
-
end
|
30
|
-
|
31
|
-
it "handles method missing for query" do
|
32
|
-
@new_user = Foo::User.new
|
33
|
-
expect { @new_user.fullname? }.not_to raise_error()
|
34
|
-
end
|
35
|
-
|
36
|
-
it "handles respond_to for getter" do
|
37
|
-
@new_user = Foo::User.new(:fullname => 'Mayonegg')
|
38
|
-
@new_user.should_not respond_to(:unknown_method_for_a_user)
|
39
|
-
@new_user.should respond_to(:fullname)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "handles respond_to for setter" do
|
43
|
-
@new_user = Foo::User.new
|
44
|
-
@new_user.should respond_to(:fullname=)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "handles respond_to for query" do
|
48
|
-
@new_user = Foo::User.new
|
49
|
-
@new_user.should respond_to(:fullname?)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "handles has_attribute? for getter" do
|
53
|
-
@new_user = Foo::User.new(:fullname => 'Mayonegg')
|
54
|
-
@new_user.should_not have_attribute(:unknown_method_for_a_user)
|
55
|
-
@new_user.should have_attribute(:fullname)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "handles get_attribute for getter" do
|
59
|
-
@new_user = Foo::User.new(:fullname => 'Mayonegg')
|
60
|
-
@new_user.get_attribute(:unknown_method_for_a_user).should be_nil
|
61
|
-
@new_user.get_attribute(:fullname).should == 'Mayonegg'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "handles get_attribute for getter with dash" do
|
65
|
-
@new_user = Foo::User.new(:'life-span' => '3 years')
|
66
|
-
@new_user.get_attribute(:unknown_method_for_a_user).should be_nil
|
67
|
-
@new_user.get_attribute(:'life-span').should == '3 years'
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
context "assigning new resource data" do
|
73
|
-
before do
|
74
|
-
spawn_model "Foo::User"
|
75
|
-
@user = Foo::User.new(:active => false)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "handles data update through #assign_attributes" do
|
79
|
-
@user.assign_attributes :active => true
|
80
|
-
@user.should be_active
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "checking resource equality" do
|
85
|
-
before do
|
86
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
87
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
88
|
-
builder.use Faraday::Request::UrlEncoded
|
89
|
-
builder.adapter :test do |stub|
|
90
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
|
91
|
-
stub.get("/users/2") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
|
92
|
-
stub.get("/admins/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke" }.to_json] }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
spawn_model "Foo::User"
|
97
|
-
spawn_model "Foo::Admin"
|
98
|
-
end
|
99
|
-
|
100
|
-
let(:user) { Foo::User.find(1) }
|
101
|
-
|
102
|
-
it "returns true for the exact same object" do
|
103
|
-
user.should == user
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns true for the same resource via find" do
|
107
|
-
user.should == Foo::User.find(1)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "returns true for the same class with identical data" do
|
111
|
-
user.should == Foo::User.new(:id => 1, :fullname => "Lindsay Fünke")
|
112
|
-
end
|
113
|
-
|
114
|
-
it "returns true for a different resource with the same data" do
|
115
|
-
user.should == Foo::Admin.find(1)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "returns false for the same class with different data" do
|
119
|
-
user.should_not == Foo::User.new(:id => 2, :fullname => "Tobias Fünke")
|
120
|
-
end
|
121
|
-
|
122
|
-
it "returns false for a non-resource with the same data" do
|
123
|
-
fake_user = double(:data => { :id => 1, :fullname => "Lindsay Fünke" })
|
124
|
-
user.should_not == fake_user
|
125
|
-
end
|
126
|
-
|
127
|
-
it "delegates eql? to ==" do
|
128
|
-
other = Object.new
|
129
|
-
user.should_receive(:==).with(other).and_return(true)
|
130
|
-
user.eql?(other).should be_truthy
|
131
|
-
end
|
132
|
-
|
133
|
-
it "treats equal resources as equal for Array#uniq" do
|
134
|
-
user2 = Foo::User.find(1)
|
135
|
-
[user, user2].uniq.should == [user]
|
136
|
-
end
|
137
|
-
|
138
|
-
it "treats equal resources as equal for hash keys" do
|
139
|
-
Foo::User.find(1)
|
140
|
-
hash = { user => true }
|
141
|
-
hash[Foo::User.find(1)] = false
|
142
|
-
hash.size.should == 1
|
143
|
-
hash.should == { user => false }
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
context "handling metadata and errors" do
|
148
|
-
before do
|
149
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
150
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
151
|
-
builder.adapter :test do |stub|
|
152
|
-
stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
spawn_model 'Foo::User' do
|
157
|
-
store_response_errors :errors
|
158
|
-
store_metadata :my_data
|
159
|
-
end
|
160
|
-
|
161
|
-
@user = Foo::User.new(:_errors => ["Foo", "Bar"], :_metadata => { :secret => true })
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should return response_errors stored in the method provided by `store_response_errors`" do
|
165
|
-
@user.errors.should == ["Foo", "Bar"]
|
166
|
-
end
|
167
|
-
|
168
|
-
it "should remove the default method for errors" do
|
169
|
-
expect { @user.response_errors }.to raise_error(NoMethodError)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should return metadata stored in the method provided by `store_metadata`" do
|
173
|
-
@user.my_data.should == { :secret => true }
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should remove the default method for metadata" do
|
177
|
-
expect { @user.metadata }.to raise_error(NoMethodError)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should work with #save" do
|
181
|
-
@user.assign_attributes(:fullname => "Tobias Fünke")
|
182
|
-
@user.save
|
183
|
-
expect { @user.metadata }.to raise_error(NoMethodError)
|
184
|
-
@user.my_data.should be_empty
|
185
|
-
@user.errors.should be_empty
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
context "overwriting default attribute methods" do
|
190
|
-
context "for getter method" do
|
191
|
-
before do
|
192
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
193
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
194
|
-
builder.adapter :test do |stub|
|
195
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
spawn_model 'Foo::User' do
|
200
|
-
def document
|
201
|
-
@attributes[:document][:url]
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "bypasses Her's method" do
|
207
|
-
@user = Foo::User.find(1)
|
208
|
-
@user.document.should == "http://example.com"
|
209
|
-
|
210
|
-
@user = Foo::User.find(1)
|
211
|
-
@user.document.should == "http://example.com"
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
context "for setter method" do
|
216
|
-
before do
|
217
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
218
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
219
|
-
builder.adapter :test do |stub|
|
220
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
spawn_model 'Foo::User' do
|
225
|
-
def document=(document)
|
226
|
-
@attributes[:document] = document[:url]
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
it "bypasses Her's method" do
|
232
|
-
@user = Foo::User.find(1)
|
233
|
-
@user.document.should == "http://example.com"
|
234
|
-
|
235
|
-
@user = Foo::User.find(1)
|
236
|
-
@user.document.should == "http://example.com"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context "for predicate method" do
|
241
|
-
before do
|
242
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
243
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
244
|
-
builder.adapter :test do |stub|
|
245
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :document => { :url => nil } }.to_json] }
|
246
|
-
stub.get("/users/2") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke", :document => { :url => "http://example.com" } }.to_json] }
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
spawn_model 'Foo::User' do
|
251
|
-
def document?
|
252
|
-
document[:url].present?
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
it "byoasses Her's method" do
|
258
|
-
@user = Foo::User.find(1)
|
259
|
-
@user.document?.should be_falsey
|
260
|
-
|
261
|
-
@user = Foo::User.find(1)
|
262
|
-
@user.document?.should be_falsey
|
263
|
-
|
264
|
-
@user = Foo::User.find(2)
|
265
|
-
@user.document?.should be_truthy
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
context "attributes class method" do
|
271
|
-
before do
|
272
|
-
spawn_model 'Foo::User' do
|
273
|
-
attributes :fullname, :document
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
context "instance" do
|
278
|
-
subject { Foo::User.new }
|
279
|
-
|
280
|
-
it { should respond_to(:fullname) }
|
281
|
-
it { should respond_to(:fullname=) }
|
282
|
-
it { should respond_to(:fullname?) }
|
283
|
-
end
|
284
|
-
|
285
|
-
it "defines setter that affects @attributes" do
|
286
|
-
user = Foo::User.new
|
287
|
-
user.fullname = 'Tobias Fünke'
|
288
|
-
user.attributes[:fullname].should eq('Tobias Fünke')
|
289
|
-
end
|
290
|
-
|
291
|
-
it "defines getter that reads @attributes" do
|
292
|
-
user = Foo::User.new
|
293
|
-
user.assign_attributes(fullname: 'Tobias Fünke')
|
294
|
-
user.fullname.should eq('Tobias Fünke')
|
295
|
-
end
|
296
|
-
|
297
|
-
it "defines predicate that reads @attributes" do
|
298
|
-
user = Foo::User.new
|
299
|
-
user.fullname?.should be_falsey
|
300
|
-
user.assign_attributes(fullname: 'Tobias Fünke')
|
301
|
-
user.fullname?.should be_truthy
|
302
|
-
end
|
303
|
-
|
304
|
-
context "when attribute methods are already defined" do
|
305
|
-
before do
|
306
|
-
class AbstractUser
|
307
|
-
attr_accessor :fullname
|
308
|
-
|
309
|
-
def fullname?
|
310
|
-
@fullname.present?
|
311
|
-
end
|
312
|
-
end
|
313
|
-
@spawned_models << :AbstractUser
|
314
|
-
|
315
|
-
spawn_model 'Foo::User', super_class: AbstractUser do
|
316
|
-
attributes :fullname
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
it "overrides getter method" do
|
321
|
-
Foo::User.generated_attribute_methods.instance_methods.should include(:fullname)
|
322
|
-
end
|
323
|
-
|
324
|
-
it "overrides setter method" do
|
325
|
-
Foo::User.generated_attribute_methods.instance_methods.should include(:fullname=)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "overrides predicate method" do
|
329
|
-
Foo::User.generated_attribute_methods.instance_methods.should include(:fullname?)
|
330
|
-
end
|
331
|
-
|
332
|
-
it "defines setter that affects @attributes" do
|
333
|
-
user = Foo::User.new
|
334
|
-
user.fullname = 'Tobias Fünke'
|
335
|
-
user.attributes[:fullname].should eq('Tobias Fünke')
|
336
|
-
end
|
337
|
-
|
338
|
-
it "defines getter that reads @attributes" do
|
339
|
-
user = Foo::User.new
|
340
|
-
user.attributes[:fullname] = 'Tobias Fünke'
|
341
|
-
user.fullname.should eq('Tobias Fünke')
|
342
|
-
end
|
343
|
-
|
344
|
-
it "defines predicate that reads @attributes" do
|
345
|
-
user = Foo::User.new
|
346
|
-
user.fullname?.should be_falsey
|
347
|
-
user.attributes[:fullname] = 'Tobias Fünke'
|
348
|
-
user.fullname?.should be_truthy
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
if ActiveModel::VERSION::MAJOR < 4
|
353
|
-
it "creates a new mutex" do
|
354
|
-
expect(Mutex).to receive(:new).once.and_call_original
|
355
|
-
spawn_model 'Foo::User' do
|
356
|
-
attributes :fullname
|
357
|
-
end
|
358
|
-
Foo::User.attribute_methods_mutex.should_not eq(Foo::User.generated_attribute_methods)
|
359
|
-
end
|
360
|
-
|
361
|
-
it "works well with Module#synchronize monkey patched by ActiveSupport" do
|
362
|
-
Module.class_eval do
|
363
|
-
def synchronize(*args)
|
364
|
-
raise 'gotcha!'
|
365
|
-
end
|
366
|
-
end
|
367
|
-
expect(Mutex).to receive(:new).once.and_call_original
|
368
|
-
spawn_model 'Foo::User' do
|
369
|
-
attributes :fullname
|
370
|
-
end
|
371
|
-
Foo::User.attribute_methods_mutex.should_not eq(Foo::User.generated_attribute_methods)
|
372
|
-
Module.class_eval do
|
373
|
-
undef :synchronize
|
374
|
-
end
|
375
|
-
end
|
376
|
-
else
|
377
|
-
it "uses ActiveModel's mutex" do
|
378
|
-
Foo::User.attribute_methods_mutex.should eq(Foo::User.generated_attribute_methods)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
it "uses a mutex" do
|
383
|
-
spawn_model 'Foo::User'
|
384
|
-
expect(Foo::User.attribute_methods_mutex).to receive(:synchronize).once.and_call_original
|
385
|
-
Foo::User.class_eval do
|
386
|
-
attributes :fullname, :documents
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
|
391
|
-
context "YAML serialization" do
|
392
|
-
before do
|
393
|
-
spawn_model 'Foo::User' do
|
394
|
-
attributes :fullname
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
it "successfully serializes and deserializes" do
|
399
|
-
user = Foo::User.new(fullname: 'bar')
|
400
|
-
revived_user = YAML.load(YAML.dump(user))
|
401
|
-
revived_user.fullname.should eq('bar')
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
3
|
-
|
4
|
-
describe "Her::Model and ActiveModel::Callbacks" do
|
5
|
-
before do
|
6
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
7
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
8
|
-
end
|
9
|
-
|
10
|
-
spawn_model "Foo::User"
|
11
|
-
end
|
12
|
-
|
13
|
-
context :before_save do
|
14
|
-
subject { Foo::User.create(:name => "Tobias Funke") }
|
15
|
-
before do
|
16
|
-
Her::API.default_api.connection.adapter :test do |stub|
|
17
|
-
stub.post("/users") { |env| [200, {}, { :id => 1, :name => env[:body][:name] }.to_json] }
|
18
|
-
stub.put("/users/1") { |env| [200, {}, { :id => 1, :name => env[:body][:name] }.to_json] }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "when using a symbol callback" do
|
23
|
-
before do
|
24
|
-
class Foo::User
|
25
|
-
before_save :alter_name
|
26
|
-
def alter_name; self.name.upcase!; end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when using a block callback" do
|
34
|
-
before do
|
35
|
-
class Foo::User
|
36
|
-
before_save lambda { self.name.upcase! }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
41
|
-
end
|
42
|
-
|
43
|
-
context "when changing a value of an existing resource in a callback" do
|
44
|
-
before do
|
45
|
-
class Foo::User
|
46
|
-
before_save :alter_name
|
47
|
-
def alter_name
|
48
|
-
self.name = "Lumberjack" if persisted?
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should call the server with the canged value" do
|
54
|
-
subject.name.should == "Tobias Funke"
|
55
|
-
subject.save
|
56
|
-
subject.name.should == "Lumberjack"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context :before_create do
|
62
|
-
subject { Foo::User.create(:name => "Tobias Funke") }
|
63
|
-
before do
|
64
|
-
Her::API.default_api.connection.adapter :test do |stub|
|
65
|
-
stub.post("/users") { |env| [200, {}, { :id => 1, :name => env[:body][:name] }.to_json] }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when using a symbol callback" do
|
70
|
-
before do
|
71
|
-
class Foo::User
|
72
|
-
before_create :alter_name
|
73
|
-
def alter_name; self.name.upcase!; end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
78
|
-
end
|
79
|
-
|
80
|
-
context "when using a block callback" do
|
81
|
-
before do
|
82
|
-
class Foo::User
|
83
|
-
before_create lambda { self.name.upcase! }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context :after_find do
|
92
|
-
subject { Foo::User.find(1) }
|
93
|
-
before do
|
94
|
-
Her::API.default_api.connection.adapter :test do |stub|
|
95
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :name => "Tobias Funke" }.to_json] }
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "when using a symbol callback" do
|
100
|
-
before do
|
101
|
-
class Foo::User
|
102
|
-
after_find :alter_name
|
103
|
-
def alter_name; self.name.upcase!; end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when using a block callback" do
|
111
|
-
before do
|
112
|
-
class Foo::User
|
113
|
-
after_find lambda { self.name.upcase! }
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context :after_initialize do
|
122
|
-
subject { Foo::User.new(:name => "Tobias Funke") }
|
123
|
-
|
124
|
-
context "when using a symbol callback" do
|
125
|
-
before do
|
126
|
-
class Foo::User
|
127
|
-
after_initialize :alter_name
|
128
|
-
def alter_name; self.name.upcase!; end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when using a block callback" do
|
136
|
-
before do
|
137
|
-
class Foo::User
|
138
|
-
after_initialize lambda { self.name.upcase! }
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
its(:name) { should == "TOBIAS FUNKE" }
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
3
|
-
|
4
|
-
describe "Her::Model and ActiveModel::Dirty" do
|
5
|
-
context "checking dirty attributes" do
|
6
|
-
before do
|
7
|
-
Her::API.setup :url => "https://api.example.com" do |builder|
|
8
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
9
|
-
builder.use Faraday::Request::UrlEncoded
|
10
|
-
builder.adapter :test do |stub|
|
11
|
-
stub.get("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Lindsay Fünke", :friends => [ { :name => "Fred" } ], :best_friend => { :name => "Dave" } }.to_json] }
|
12
|
-
stub.get("/users/2") { |env| [200, {}, { :id => 2, :fullname => "Maeby Fünke" }.to_json] }
|
13
|
-
stub.get("/users/3") { |env| [200, {}, { :user_id => 3, :fullname => "Maeby Fünke" }.to_json] }
|
14
|
-
stub.put("/users/1") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
|
15
|
-
stub.put("/users/2") { |env| [400, {}, { :errors => ["Email cannot be blank"] }.to_json] }
|
16
|
-
stub.post("/users") { |env| [200, {}, { :id => 1, :fullname => "Tobias Fünke" }.to_json] }
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
spawn_model "Foo::Friend" do
|
21
|
-
attributes :name
|
22
|
-
end
|
23
|
-
spawn_model "Foo::User" do
|
24
|
-
has_many :friends, class_name: "Foo::Friend"
|
25
|
-
has_one :best_friend, class_name: "Foo::Friend"
|
26
|
-
|
27
|
-
attributes :fullname, :email
|
28
|
-
end
|
29
|
-
spawn_model "Dynamic::User" do
|
30
|
-
primary_key :user_id
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "for existing resource" do
|
35
|
-
let(:user) { Foo::User.find(1) }
|
36
|
-
it "has no changes" do
|
37
|
-
user.changes.should be_empty
|
38
|
-
user.should_not be_changed
|
39
|
-
end
|
40
|
-
|
41
|
-
context "for has_many associations" do
|
42
|
-
it "has no changes" do
|
43
|
-
user.friends.first.name_changed?.should eq false
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "for has_one associations" do
|
48
|
-
it "has no changes" do
|
49
|
-
user.best_friend.name_changed?.should eq false
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "with successful save" do
|
54
|
-
it "tracks dirty attributes" do
|
55
|
-
user.fullname = "Tobias Fünke"
|
56
|
-
user.fullname_changed?.should be_truthy
|
57
|
-
user.email_changed?.should be_falsey
|
58
|
-
user.should be_changed
|
59
|
-
user.save
|
60
|
-
user.should_not be_changed
|
61
|
-
end
|
62
|
-
|
63
|
-
it "tracks only changed dirty attributes" do
|
64
|
-
user.fullname = user.fullname
|
65
|
-
user.fullname_changed?.should be_falsey
|
66
|
-
end
|
67
|
-
|
68
|
-
it "tracks previous changes" do
|
69
|
-
user.fullname = "Tobias Fünke"
|
70
|
-
user.save
|
71
|
-
user.previous_changes.should eq({"fullname"=>"Lindsay Fünke"})
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'tracks dirty attribute for mass assign for dynamic created attributes' do
|
75
|
-
user = Dynamic::User.find(3)
|
76
|
-
user.assign_attributes(:fullname => 'New Fullname')
|
77
|
-
user.fullname_changed?.should be_truthy
|
78
|
-
user.should be_changed
|
79
|
-
user.changes.length.should eq(1)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "with erroneous save" do
|
84
|
-
it "tracks dirty attributes" do
|
85
|
-
user = Foo::User.find(2)
|
86
|
-
user.fullname = "Tobias Fünke"
|
87
|
-
user.fullname_changed?.should be_truthy
|
88
|
-
user.email_changed?.should be_falsey
|
89
|
-
user.should be_changed
|
90
|
-
user.save
|
91
|
-
user.should be_changed
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "for new resource" do
|
97
|
-
let(:user) { Foo::User.new(:fullname => "Lindsay Fünke") }
|
98
|
-
it "has changes" do
|
99
|
-
user.should be_changed
|
100
|
-
end
|
101
|
-
it "tracks dirty attributes" do
|
102
|
-
user.fullname = "Tobias Fünke"
|
103
|
-
user.fullname_changed?.should be_truthy
|
104
|
-
user.should be_changed
|
105
|
-
user.save
|
106
|
-
user.should_not be_changed
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|