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
data/vendor/gems/her/Rakefile
DELETED
data/vendor/gems/her/UPGRADE.md
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
# Upgrade Her
|
2
|
-
|
3
|
-
Here is a list of notable changes by release. Her follows the [Semantic Versioning](http://semver.org/) system.
|
4
|
-
|
5
|
-
## 0.8.0
|
6
|
-
|
7
|
-
- Initial support for JSONAPI [link](https://github.com/remiprev/her/pull/347)
|
8
|
-
- Fix for has_one association parsing [link](https://github.com/remiprev/her/pull/352)
|
9
|
-
- Fix for escaping path variables HT @marshall-lee [link](https://github.com/remiprev/her/pull/354)
|
10
|
-
- Fix syntax highlighting in README HT @tippenein [link](https://github.com/remiprev/her/pull/356)
|
11
|
-
- Fix associations with Active Model Serializers HT @minktom [link](https://github.com/remiprev/her/pull/359)
|
12
|
-
|
13
|
-
## 0.7.6
|
14
|
-
|
15
|
-
- Loosen restrictions on ActiveSupport and ActiveModel to accommodate security fixes [link](https://github.com/remiprev/her/commit/8ff641fcdaf14be7cc9b1a6ee6654f27f7dfa34c)
|
16
|
-
|
17
|
-
## 0.7.5
|
18
|
-
|
19
|
-
- Performance fix for responses with large number of objects [link](https://github.com/remiprev/her/pull/337)
|
20
|
-
- Bugfix for dirty attributes [link](https://github.com/remiprev/her/commit/70285debc6837a33a3a750c7c4a7251439464b42)
|
21
|
-
- Add ruby 2.1 and 2.2 to travis test run. We will likely be removing official 1.9.x support in the near future, and
|
22
|
-
will begin to align our support with the official ruby maintenance schedule.
|
23
|
-
- README updates
|
24
|
-
|
25
|
-
## 0.6
|
26
|
-
|
27
|
-
Associations have been refactored so that calling the association name method doesn’t immediately load or fetch the data.
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
class User
|
31
|
-
include Her::Model
|
32
|
-
has_many :comments
|
33
|
-
end
|
34
|
-
|
35
|
-
# This doesn’t fetch the data yet and it’s still chainable
|
36
|
-
comments = User.find(1).comments
|
37
|
-
|
38
|
-
# This actually fetches the data
|
39
|
-
puts comments.inspect
|
40
|
-
|
41
|
-
# This is no longer possible in her-0.6
|
42
|
-
comments = User.find(1).comments(:approved => 1)
|
43
|
-
|
44
|
-
# To pass additional parameters to the HTTP request, we now have to do this
|
45
|
-
comments = User.find(1).comments.where(:approved => 1)
|
46
|
-
```
|
47
|
-
|
48
|
-
## 0.5
|
49
|
-
|
50
|
-
Her is now compatible with `ActiveModel` and includes `ActiveModel::Validations`.
|
51
|
-
|
52
|
-
Before 0.5, the `errors` method on an object would return an error list received from the server (the `:errors` key defined by the parsing middleware). But now, `errors` returns the error list generated after calling the `valid?` method (or any other similar validation method from `ActiveModel::Validations`). The error list returned from the server is now accessible from the `response_errors` method.
|
53
|
-
|
54
|
-
Since 0.5.5, Her provides a `store_response_errors` method, which allows you to choose the method which will return the response errors. You can use it to revert Her back to its original behavior (ie. `errors` returning the response errors):
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
class User
|
58
|
-
include Her::Model
|
59
|
-
store_response_errors :errors
|
60
|
-
end
|
61
|
-
|
62
|
-
user = User.create(:email => "foo") # POST /users returns { :errors => ["Email is invalid"] }
|
63
|
-
user.errors # => ["Email is invalid"]
|
64
|
-
```
|
65
|
-
|
66
|
-
## 0.2.4
|
67
|
-
|
68
|
-
Her no longer includes default middleware when making HTTP requests. The user has now to define all the needed middleware. Before:
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
Her::API.setup :url => "https://api.example.com" do |connection|
|
72
|
-
connection.insert(0, FaradayMiddle::OAuth)
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
|
-
Now:
|
77
|
-
|
78
|
-
```ruby
|
79
|
-
Her::API.setup :url => "https://api.example.com" do |connection|
|
80
|
-
connection.use FaradayMiddle::OAuth
|
81
|
-
connection.use Her::Middleware::FirstLevelParseJSON
|
82
|
-
connection.use Faraday::Request::UrlEncoded
|
83
|
-
connection.use Faraday::Adapter::NetHttp
|
84
|
-
end
|
85
|
-
```
|
86
|
-
|
87
|
-
## 0.2
|
88
|
-
|
89
|
-
The default parser middleware has been replaced to treat first-level JSON data as the resource or collection data. Before it expected this:
|
90
|
-
|
91
|
-
```json
|
92
|
-
{ "data": { "id": 1, "name": "Foo" }, "errors": [] }
|
93
|
-
```
|
94
|
-
|
95
|
-
Now it expects this (the `errors` key is not treated as resource data):
|
96
|
-
|
97
|
-
```json
|
98
|
-
{ "id": 1, "name": "Foo", "errors": [] }
|
99
|
-
```
|
100
|
-
|
101
|
-
If you still want to get the old behavior, you can use `Her::Middleware::SecondLevelParseJSON` instead of `Her::Middleware::FirstLevelParseJSON` in your middleware stack.
|
@@ -1,114 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.join(File.dirname(__FILE__), "spec_helper.rb")
|
3
|
-
|
4
|
-
describe Her::API do
|
5
|
-
subject { Her::API.new }
|
6
|
-
|
7
|
-
context "initialization" do
|
8
|
-
describe "#setup" do
|
9
|
-
context "when setting custom middleware" do
|
10
|
-
before do
|
11
|
-
class Foo; end;
|
12
|
-
class Bar; end;
|
13
|
-
|
14
|
-
subject.setup :url => "https://api.example.com" do |connection|
|
15
|
-
connection.use Foo
|
16
|
-
connection.use Bar
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
specify { subject.connection.builder.handlers.should == [Foo, Bar] }
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when setting custom options" do
|
24
|
-
before { subject.setup :foo => { :bar => "baz" }, :url => "https://api.example.com" }
|
25
|
-
its(:options) { should == { :foo => { :bar => "baz" }, :url => "https://api.example.com" } }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#request" do
|
30
|
-
before do
|
31
|
-
class SimpleParser < Faraday::Response::Middleware
|
32
|
-
def on_complete(env)
|
33
|
-
env[:body] = { :data => env[:body] }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "making HTTP requests" do
|
39
|
-
let(:parsed_data) { subject.request(:_method => :get, :_path => "/foo")[:parsed_data] }
|
40
|
-
before do
|
41
|
-
subject.setup :url => "https://api.example.com" do |builder|
|
42
|
-
builder.use SimpleParser
|
43
|
-
builder.adapter(:test) { |stub| stub.get("/foo") { |env| [200, {}, "Foo, it is."] } }
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
specify { parsed_data[:data].should == "Foo, it is." }
|
48
|
-
end
|
49
|
-
|
50
|
-
context "making HTTP requests while specifying custom HTTP headers" do
|
51
|
-
let(:parsed_data) { subject.request(:_method => :get, :_path => "/foo", :_headers => { "X-Page" => 2 })[:parsed_data] }
|
52
|
-
|
53
|
-
before do
|
54
|
-
subject.setup :url => "https://api.example.com" do |builder|
|
55
|
-
builder.use SimpleParser
|
56
|
-
builder.adapter(:test) { |stub| stub.get("/foo") { |env| [200, {}, "Foo, it is page #{env[:request_headers]["X-Page"]}."] } }
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
specify { parsed_data[:data].should == "Foo, it is page 2." }
|
61
|
-
end
|
62
|
-
|
63
|
-
context "parsing a request with the default parser" do
|
64
|
-
let(:parsed_data) { subject.request(:_method => :get, :_path => "users/1")[:parsed_data] }
|
65
|
-
before do
|
66
|
-
subject.setup :url => "https://api.example.com" do |builder|
|
67
|
-
builder.use Her::Middleware::FirstLevelParseJSON
|
68
|
-
builder.adapter :test do |stub|
|
69
|
-
stub.get("/users/1") { |env| [200, {}, MultiJson.dump({ :id => 1, :name => "George Michael Bluth", :errors => ["This is a single error"], :metadata => { :page => 1, :per_page => 10 } })] }
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
specify do
|
75
|
-
parsed_data[:data].should == { :id => 1, :name => "George Michael Bluth" }
|
76
|
-
parsed_data[:errors].should == ["This is a single error"]
|
77
|
-
parsed_data[:metadata].should == { :page => 1, :per_page => 10 }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "parsing a request with a custom parser" do
|
82
|
-
let(:parsed_data) { subject.request(:_method => :get, :_path => "users/1")[:parsed_data] }
|
83
|
-
before do
|
84
|
-
class CustomParser < Faraday::Response::Middleware
|
85
|
-
def on_complete(env)
|
86
|
-
json = MultiJson.load(env[:body], :symbolize_keys => true)
|
87
|
-
errors = json.delete(:errors) || []
|
88
|
-
metadata = json.delete(:metadata) || {}
|
89
|
-
env[:body] = {
|
90
|
-
:data => json,
|
91
|
-
:errors => errors,
|
92
|
-
:metadata => metadata,
|
93
|
-
}
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
subject.setup :url => "https://api.example.com" do |builder|
|
98
|
-
builder.use CustomParser
|
99
|
-
builder.use Faraday::Request::UrlEncoded
|
100
|
-
builder.adapter :test do |stub|
|
101
|
-
stub.get("/users/1") { |env| [200, {}, MultiJson.dump(:id => 1, :name => "George Michael Bluth")] }
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
specify do
|
107
|
-
parsed_data[:data].should == { :id => 1, :name => "George Michael Bluth" }
|
108
|
-
parsed_data[:errors].should == []
|
109
|
-
parsed_data[:metadata].should == {}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Her::Collection do
|
4
|
-
|
5
|
-
let(:items) { [1, 2, 3, 4] }
|
6
|
-
let(:metadata) { { :name => 'Testname' } }
|
7
|
-
let(:errors) { { :name => ['not_present'] } }
|
8
|
-
|
9
|
-
describe "#new" do
|
10
|
-
context "without parameters" do
|
11
|
-
subject { Her::Collection.new }
|
12
|
-
|
13
|
-
it { should eq([]) }
|
14
|
-
its(:metadata) { should eq({}) }
|
15
|
-
its(:errors) { should eq({}) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "with parameters" do
|
19
|
-
subject { Her::Collection.new(items, metadata, errors) }
|
20
|
-
|
21
|
-
it { should eq([1,2,3,4]) }
|
22
|
-
its(:metadata) { should eq({ :name => 'Testname' }) }
|
23
|
-
its(:errors) { should eq({ :name => ['not_present'] }) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Her::ErrorCollection do
|
4
|
-
|
5
|
-
let(:metadata) { { :name => 'Testname' } }
|
6
|
-
let(:errors) { { :name => ['not_present'] } }
|
7
|
-
|
8
|
-
describe "#new" do
|
9
|
-
context "without parameters" do
|
10
|
-
subject { Her::ErrorCollection.new }
|
11
|
-
|
12
|
-
it "raises upon access" do
|
13
|
-
expect { subject[0] }.to raise_error(Her::Errors::ResponseError, "Cannot access collection, Request returned an error")
|
14
|
-
expect { subject.last }.to raise_error(Her::Errors::ResponseError, "Cannot access collection, Request returned an error")
|
15
|
-
end
|
16
|
-
|
17
|
-
its(:metadata) { should eq({}) }
|
18
|
-
its(:errors) { should eq({}) }
|
19
|
-
end
|
20
|
-
|
21
|
-
context "with parameters" do
|
22
|
-
subject { Her::ErrorCollection.new(metadata, errors) }
|
23
|
-
|
24
|
-
it "raises upon access" do
|
25
|
-
expect { subject[0] }.to raise_error(Her::Errors::ResponseError, "Cannot access collection, Request returned an error")
|
26
|
-
expect { subject.last }.to raise_error(Her::Errors::ResponseError, "Cannot access collection, Request returned an error")
|
27
|
-
end
|
28
|
-
|
29
|
-
its(:metadata) { should eq({ :name => 'Testname' }) }
|
30
|
-
its(:errors) { should eq({ :name => ['not_present'] }) }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Her::JsonApi::Model do
|
4
|
-
before do
|
5
|
-
Her::API.setup :url => "https://api.example.com" do |connection|
|
6
|
-
connection.use Her::Middleware::JsonApiParser
|
7
|
-
connection.adapter :test do |stub|
|
8
|
-
stub.get("/users/1") do |env|
|
9
|
-
[
|
10
|
-
200,
|
11
|
-
{},
|
12
|
-
{
|
13
|
-
data: {
|
14
|
-
id: 1,
|
15
|
-
type: 'users',
|
16
|
-
attributes: {
|
17
|
-
name: "Roger Federer",
|
18
|
-
},
|
19
|
-
}
|
20
|
-
|
21
|
-
}.to_json
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
stub.get("/users") do |env|
|
26
|
-
[
|
27
|
-
200,
|
28
|
-
{},
|
29
|
-
{
|
30
|
-
data: [
|
31
|
-
{
|
32
|
-
id: 1,
|
33
|
-
type: 'users',
|
34
|
-
attributes: {
|
35
|
-
name: "Roger Federer",
|
36
|
-
},
|
37
|
-
},
|
38
|
-
{
|
39
|
-
id: 2,
|
40
|
-
type: 'users',
|
41
|
-
attributes: {
|
42
|
-
name: "Kei Nishikori",
|
43
|
-
},
|
44
|
-
}
|
45
|
-
]
|
46
|
-
}.to_json
|
47
|
-
]
|
48
|
-
end
|
49
|
-
|
50
|
-
stub.post("/users", data: {
|
51
|
-
type: 'users',
|
52
|
-
attributes: {
|
53
|
-
name: "Jeremy Lin",
|
54
|
-
},
|
55
|
-
}) do |env|
|
56
|
-
[
|
57
|
-
201,
|
58
|
-
{},
|
59
|
-
{
|
60
|
-
data: {
|
61
|
-
id: 3,
|
62
|
-
type: 'users',
|
63
|
-
attributes: {
|
64
|
-
name: 'Jeremy Lin',
|
65
|
-
},
|
66
|
-
}
|
67
|
-
|
68
|
-
}.to_json
|
69
|
-
]
|
70
|
-
end
|
71
|
-
|
72
|
-
stub.patch("/users/1", data: {
|
73
|
-
type: 'users',
|
74
|
-
id: 1,
|
75
|
-
attributes: {
|
76
|
-
name: "Fed GOAT",
|
77
|
-
},
|
78
|
-
}) do |env|
|
79
|
-
[
|
80
|
-
200,
|
81
|
-
{},
|
82
|
-
{
|
83
|
-
data: {
|
84
|
-
id: 1,
|
85
|
-
type: 'users',
|
86
|
-
attributes: {
|
87
|
-
name: 'Fed GOAT',
|
88
|
-
},
|
89
|
-
}
|
90
|
-
|
91
|
-
}.to_json
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
stub.delete("/users/1") { |env|
|
96
|
-
[ 204, {}, {}, ]
|
97
|
-
}
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
spawn_model("Foo::User", type: Her::JsonApi::Model)
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'allows configuration of type' do
|
106
|
-
spawn_model("Foo::Bar", type: Her::JsonApi::Model) do
|
107
|
-
type :foobars
|
108
|
-
end
|
109
|
-
|
110
|
-
expect(Foo::Bar.instance_variable_get('@type')).to eql('foobars')
|
111
|
-
end
|
112
|
-
|
113
|
-
it 'finds models by id' do
|
114
|
-
user = Foo::User.find(1)
|
115
|
-
expect(user.attributes).to eql(
|
116
|
-
'id' => 1,
|
117
|
-
'name' => 'Roger Federer',
|
118
|
-
)
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'finds a collection of models' do
|
122
|
-
users = Foo::User.all
|
123
|
-
expect(users.map(&:attributes)).to match_array([
|
124
|
-
{
|
125
|
-
'id' => 1,
|
126
|
-
'name' => 'Roger Federer',
|
127
|
-
},
|
128
|
-
{
|
129
|
-
'id' => 2,
|
130
|
-
'name' => 'Kei Nishikori',
|
131
|
-
}
|
132
|
-
])
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'creates a Foo::User' do
|
136
|
-
user = Foo::User.new(name: 'Jeremy Lin')
|
137
|
-
user.save
|
138
|
-
expect(user.attributes).to eql(
|
139
|
-
'id' => 3,
|
140
|
-
'name' => 'Jeremy Lin',
|
141
|
-
'status_code' => 201
|
142
|
-
)
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'updates a Foo::User' do
|
146
|
-
user = Foo::User.find(1)
|
147
|
-
user.name = 'Fed GOAT'
|
148
|
-
user.save
|
149
|
-
expect(user.attributes).to eql(
|
150
|
-
'id' => 1,
|
151
|
-
'name' => 'Fed GOAT',
|
152
|
-
'status_code' => 200
|
153
|
-
)
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'destroys a Foo::User' do
|
157
|
-
user = Foo::User.find(1)
|
158
|
-
expect(user.destroy).to be_destroyed
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'undefined methods' do
|
162
|
-
it 'removes methods that are not compatible with json api' do
|
163
|
-
[:parse_root_in_json, :include_root_in_json, :root_element, :primary_key].each do |method|
|
164
|
-
expect { Foo::User.new.send(method, :foo) }.to raise_error NoMethodError, "Her::JsonApi::Model does not support the #{method} configuration option"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Her::Middleware::FirstLevelParseJSON do
|
5
|
-
subject { described_class.new }
|
6
|
-
let(:body_without_errors) { "{\"id\": 1, \"name\": \"Tobias Fünke\", \"metadata\": 3}" }
|
7
|
-
let(:body_with_errors) { "{\"id\": 1, \"name\": \"Tobias Fünke\", \"errors\": { \"name\": [ \"not_valid\", \"should_be_present\" ] }, \"metadata\": 3}" }
|
8
|
-
let(:body_with_malformed_json) { "wut." }
|
9
|
-
let(:body_with_invalid_json) { "true" }
|
10
|
-
let(:empty_body) { '' }
|
11
|
-
let(:nil_body) { nil }
|
12
|
-
|
13
|
-
it "parses body as json" do
|
14
|
-
subject.parse(body_without_errors).tap do |json|
|
15
|
-
json[:data].should == { :id => 1, :name => "Tobias Fünke" }
|
16
|
-
json[:metadata].should == 3
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it "parses :body key as json in the env hash" do
|
21
|
-
env = { :body => body_without_errors }
|
22
|
-
subject.on_complete(env)
|
23
|
-
env[:body].tap do |json|
|
24
|
-
json[:data].should == { :id => 1, :name => "Tobias Fünke" }
|
25
|
-
json[:metadata].should == 3
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'ensures the errors are a hash if there are no errors' do
|
30
|
-
subject.parse(body_without_errors)[:errors].should eq({})
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'ensures the errors are a hash if there are no errors' do
|
34
|
-
subject.parse(body_with_errors)[:errors].should eq({:name => [ 'not_valid', 'should_be_present']})
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'ensures that malformed JSON throws an exception' do
|
38
|
-
expect { subject.parse(body_with_malformed_json) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "wut.")')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'ensures that invalid JSON throws an exception' do
|
42
|
-
expect { subject.parse(body_with_invalid_json) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "true")')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'ensures that a nil response returns an empty hash' do
|
46
|
-
subject.parse(nil_body)[:data].should eq({})
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'ensures that an empty response returns an empty hash' do
|
50
|
-
subject.parse(empty_body)[:data].should eq({})
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'with status code 204' do
|
54
|
-
it 'returns an empty body' do
|
55
|
-
env = { :status => 204 }
|
56
|
-
subject.on_complete(env)
|
57
|
-
env[:body].tap do |json|
|
58
|
-
json[:data].should == { }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Her::Middleware::JsonApiParser do
|
5
|
-
subject { described_class.new }
|
6
|
-
|
7
|
-
context "with valid JSON body" do
|
8
|
-
let(:body) { '{"data": {"type": "foo", "id": "bar", "attributes": {"baz": "qux"} }, "meta": {"api": "json api"} }' }
|
9
|
-
let(:env) { { body: body } }
|
10
|
-
|
11
|
-
it "parses body as json" do
|
12
|
-
subject.on_complete(env)
|
13
|
-
env.fetch(:body).tap do |json|
|
14
|
-
expect(json[:data]).to eql(
|
15
|
-
:type => "foo",
|
16
|
-
:id => "bar",
|
17
|
-
:attributes => { :baz => "qux" }
|
18
|
-
)
|
19
|
-
expect(json[:errors]).to eql([])
|
20
|
-
expect(json[:metadata]).to eql(:api => "json api")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
#context "with invalid JSON body" do
|
26
|
-
# let(:body) { '"foo"' }
|
27
|
-
# it 'ensures that invalid JSON throws an exception' do
|
28
|
-
# expect { subject.parse(body) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "\"foo\"")')
|
29
|
-
# end
|
30
|
-
#end
|
31
|
-
|
32
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Her::Middleware::SecondLevelParseJSON do
|
5
|
-
subject { described_class.new }
|
6
|
-
|
7
|
-
context "with valid JSON body" do
|
8
|
-
let(:body) { "{\"data\": 1, \"errors\": 2, \"metadata\": 3}" }
|
9
|
-
it "parses body as json" do
|
10
|
-
subject.parse(body).tap do |json|
|
11
|
-
json[:data].should == 1
|
12
|
-
json[:errors].should == 2
|
13
|
-
json[:metadata].should == 3
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "parses :body key as json in the env hash" do
|
18
|
-
env = { :body => body }
|
19
|
-
subject.on_complete(env)
|
20
|
-
env[:body].tap do |json|
|
21
|
-
json[:data].should == 1
|
22
|
-
json[:errors].should == 2
|
23
|
-
json[:metadata].should == 3
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "with invalid JSON body" do
|
29
|
-
let(:body) { '"foo"' }
|
30
|
-
it 'ensures that invalid JSON throws an exception' do
|
31
|
-
expect { subject.parse(body) }.to raise_error(Her::Errors::ParseError, 'Response from the API must behave like a Hash or an Array (last JSON response was "\"foo\"")')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
|
-
|
4
|
-
describe Her::Model::Associations::AssociationProxy do
|
5
|
-
describe "proxy assignment methods" 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, :name => "Tobias Fünke" }.to_json ] }
|
12
|
-
stub.get("/users/1/fish") { |env| [200, {}, { :id => 1, :name => "Tobias's Fish" }.to_json ] }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
spawn_model "User" do
|
16
|
-
has_one :fish
|
17
|
-
end
|
18
|
-
spawn_model "Fish"
|
19
|
-
end
|
20
|
-
|
21
|
-
subject { User.find(1) }
|
22
|
-
|
23
|
-
it "should assign value" do
|
24
|
-
subject.fish.name = "Fishy"
|
25
|
-
expect(subject.fish.name).to eq "Fishy"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
|