jirafe 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +5 -0
- data/.gitignore +23 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +8 -0
- data/LICENSE +13 -0
- data/README.md +104 -0
- data/Rakefile +27 -0
- data/fixtures/responses/application_get_with_cloud_token.yml +40 -0
- data/fixtures/responses/application_get_with_invalid_token.yml +41 -0
- data/fixtures/responses/application_get_with_master_token.yml +784 -0
- data/fixtures/responses/application_get_with_reporting_token.yml +38 -0
- data/fixtures/responses/application_post_with_app_token.yml +38 -0
- data/fixtures/responses/application_post_with_cloud_token.yml +76 -0
- data/fixtures/responses/application_post_with_invalid_token.yml +79 -0
- data/fixtures/responses/application_post_with_master_token.yml +784 -0
- data/fixtures/responses/application_post_with_master_token_blank_name.yml +79 -0
- data/fixtures/responses/application_post_with_master_token_dupe_name.yml +76 -0
- data/fixtures/responses/application_post_with_master_token_no_name.yml +79 -0
- data/fixtures/responses/application_post_with_reporting_token.yml +76 -0
- data/fixtures/responses/application_put_with_cloud_token.yml +68 -0
- data/fixtures/responses/application_put_with_invalid_token.yml +145 -0
- data/fixtures/responses/application_put_with_master_token.yml +68 -0
- data/fixtures/responses/application_put_with_reporting_token.yml +68 -0
- data/fixtures/responses/application_sites_get_with_master_token.yml +38 -0
- data/fixtures/responses/callback_event_post_event.yml +2000 -0
- data/fixtures/responses/callback_event_post_event_fetch_token.yml +1473 -0
- data/fixtures/responses/jirafe_resource_get_status_url.yml +38 -0
- data/fixtures/responses/jirafe_resource_get_status_url_with_query_param.yml +38 -0
- data/fixtures/responses/site_abandon_rate_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_abandoned_average_ordervalue_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_abandoned_carts_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_abandoned_revenue_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_average_order_value_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_bounces_rate_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_cart_segmentation_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_conversion_rate_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_conversions_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_customers_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_dashboard_get_with_master_token.yml +60 -0
- data/fixtures/responses/site_get_with_master_token.yml +73 -0
- data/fixtures/responses/site_keywords_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_orders_status_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_origins_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_period_data_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_post_with_app_token.yml +727 -0
- data/fixtures/responses/site_post_with_master_token.yml +1569 -0
- data/fixtures/responses/site_products_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_referers_get_with_master_token.yml +38 -0
- data/fixtures/responses/site_revenues_average_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_revenues_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_segments_carts_get_with_admin_token.yml +108 -0
- data/fixtures/responses/site_segments_sales_get_with_admin_token.yml +143 -0
- data/fixtures/responses/site_total_carts_get_with_master_token.yml +49 -0
- data/fixtures/responses/site_translations__get_with_master_token.yml +155 -0
- data/fixtures/responses/site_translations_de_get_with_master_token.yml +156 -0
- data/fixtures/responses/site_translations_es_get_with_master_token.yml +155 -0
- data/fixtures/responses/site_translations_fr_get_with_master_token.yml +178 -0
- data/fixtures/responses/site_translations_german_get_with_master_token.yml +156 -0
- data/fixtures/responses/site_translations_get_with_master_token.yml +865 -0
- data/fixtures/responses/site_translations_xx_get_with_master_token.yml +155 -0
- data/fixtures/responses/site_visits_get_with_master_token.yml +49 -0
- data/fixtures/responses/status_get.yml +38 -0
- data/fixtures/responses/status_get_500.yml +31 -0
- data/fixtures/responses/test.yml +7364 -0
- data/fixtures/responses/version_get.yml +38 -0
- data/jirafe.gemspec +29 -0
- data/lib/jirafe.rb +64 -0
- data/lib/jirafe/callback/event.rb +57 -0
- data/lib/jirafe/callback/events/order.rb +48 -0
- data/lib/jirafe/callback/events/refund.rb +32 -0
- data/lib/jirafe/callback/jirafe_callback.rb +50 -0
- data/lib/jirafe/configuration.rb +47 -0
- data/lib/jirafe/error.rb +57 -0
- data/lib/jirafe/resource/application.rb +18 -0
- data/lib/jirafe/resource/jirafe_resource.rb +188 -0
- data/lib/jirafe/resource/site.rb +21 -0
- data/lib/jirafe/resource/sites/abandon_rate.rb +16 -0
- data/lib/jirafe/resource/sites/abandoned_average_order_value.rb +17 -0
- data/lib/jirafe/resource/sites/abandoned_carts.rb +16 -0
- data/lib/jirafe/resource/sites/abandoned_revenue.rb +16 -0
- data/lib/jirafe/resource/sites/average_order_value.rb +16 -0
- data/lib/jirafe/resource/sites/bounces_rate.rb +16 -0
- data/lib/jirafe/resource/sites/cart_segmentation.rb +11 -0
- data/lib/jirafe/resource/sites/conversion_rate.rb +16 -0
- data/lib/jirafe/resource/sites/conversions.rb +17 -0
- data/lib/jirafe/resource/sites/customers.rb +16 -0
- data/lib/jirafe/resource/sites/dashboard.rb +27 -0
- data/lib/jirafe/resource/sites/keywords.rb +11 -0
- data/lib/jirafe/resource/sites/orders_status.rb +15 -0
- data/lib/jirafe/resource/sites/origins.rb +11 -0
- data/lib/jirafe/resource/sites/period_data.rb +16 -0
- data/lib/jirafe/resource/sites/products.rb +12 -0
- data/lib/jirafe/resource/sites/referers.rb +12 -0
- data/lib/jirafe/resource/sites/revenues.rb +16 -0
- data/lib/jirafe/resource/sites/revenues_average.rb +16 -0
- data/lib/jirafe/resource/sites/segments_carts.rb +14 -0
- data/lib/jirafe/resource/sites/segments_sales.rb +14 -0
- data/lib/jirafe/resource/sites/total_carts.rb +16 -0
- data/lib/jirafe/resource/sites/translations.rb +18 -0
- data/lib/jirafe/resource/sites/visitors_interest.rb +14 -0
- data/lib/jirafe/resource/sites/visits.rb +16 -0
- data/lib/jirafe/resource/status.rb +19 -0
- data/lib/jirafe/resource/sync_service.rb +1 -0
- data/lib/jirafe/resource/time_series.rb +29 -0
- data/lib/jirafe/resource/user.rb +32 -0
- data/lib/jirafe/resource/version.rb +9 -0
- data/spec/jirafe/callback/event_spec.rb +85 -0
- data/spec/jirafe/configuration_spec.rb +150 -0
- data/spec/jirafe/jirafe_spec.rb +23 -0
- data/spec/jirafe/resource/application_spec.rb +220 -0
- data/spec/jirafe/resource/jirafe_resource_spec.rb +188 -0
- data/spec/jirafe/resource/site_spec.rb +61 -0
- data/spec/jirafe/resource/sites/abandon_rate_spec.rb +11 -0
- data/spec/jirafe/resource/sites/abandoned_average_order_value_spec.rb +11 -0
- data/spec/jirafe/resource/sites/abandoned_carts_spec.rb +11 -0
- data/spec/jirafe/resource/sites/abandoned_revenue_spec.rb +11 -0
- data/spec/jirafe/resource/sites/average_order_value_spec.rb +11 -0
- data/spec/jirafe/resource/sites/bounces_rate_spec.rb +11 -0
- data/spec/jirafe/resource/sites/cart_segmentation_spec.rb +11 -0
- data/spec/jirafe/resource/sites/conversion_rate_spec.rb +11 -0
- data/spec/jirafe/resource/sites/conversions_spec.rb +11 -0
- data/spec/jirafe/resource/sites/customers_spec.rb +11 -0
- data/spec/jirafe/resource/sites/dashboard_spec.rb +29 -0
- data/spec/jirafe/resource/sites/keywords_spec.rb +11 -0
- data/spec/jirafe/resource/sites/orders_status_spec.rb +34 -0
- data/spec/jirafe/resource/sites/origins_spec.rb +11 -0
- data/spec/jirafe/resource/sites/period_data_spec.rb +22 -0
- data/spec/jirafe/resource/sites/products_spec.rb +11 -0
- data/spec/jirafe/resource/sites/referers_spec.rb +11 -0
- data/spec/jirafe/resource/sites/revenues_average_spec.rb +11 -0
- data/spec/jirafe/resource/sites/revenues_spec.rb +11 -0
- data/spec/jirafe/resource/sites/segments_carts_spec.rb +29 -0
- data/spec/jirafe/resource/sites/segments_sales_spec.rb +29 -0
- data/spec/jirafe/resource/sites/total_carts_spec.rb +11 -0
- data/spec/jirafe/resource/sites/translations_spec.rb +76 -0
- data/spec/jirafe/resource/sites/visitors_interest_spec.rb +8 -0
- data/spec/jirafe/resource/sites/visits_spec.rb +11 -0
- data/spec/jirafe/resource/status_spec.rb +31 -0
- data/spec/jirafe/resource/version_spec.rb +15 -0
- data/spec/spec_helper.rb +58 -0
- data/spec/support/callback_server.rb +11 -0
- data/spec/support/response_helper.rb +31 -0
- data/spec/support/shared_examples/empty_resource.rb +17 -0
- data/spec/support/shared_examples/time_series.rb +31 -0
- data/spec/test_configuration.rb +15 -0
- metadata +360 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jirafe do
|
4
|
+
describe ".configure" do
|
5
|
+
before { Jirafe::Configuration.instance.reset! }
|
6
|
+
after { Jirafe::Configuration.instance.reset! }
|
7
|
+
|
8
|
+
it "should set all values on the configuration instance" do
|
9
|
+
Jirafe.configure do |config|
|
10
|
+
config.url = "http://myurl"
|
11
|
+
config.token = "sometoken"
|
12
|
+
config.test = false
|
13
|
+
config.logger = Logger.new('/dev/null')
|
14
|
+
end
|
15
|
+
instance = Jirafe::Configuration.instance
|
16
|
+
instance.url.should == "http://myurl"
|
17
|
+
instance.token = "sometoken"
|
18
|
+
instance.test.should be_false
|
19
|
+
instance.logger.should be_instance_of(Logger)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jirafe::Resource::Application do
|
4
|
+
let(:resource_class) { Jirafe::Resource::Application }
|
5
|
+
let(:application_id) { 1 }
|
6
|
+
let(:application_name) { "my application" }
|
7
|
+
|
8
|
+
describe ".retrieve" do
|
9
|
+
subject { make_request(cassette) { resource_class.retrieve(application_id) } }
|
10
|
+
|
11
|
+
context "when the token is the master token" do
|
12
|
+
before { use_master_token }
|
13
|
+
let(:cassette) { "application_get_with_master_token" }
|
14
|
+
its(:class) { should == Jirafe::Resource::Application }
|
15
|
+
its(:identifier) { should == application_id }
|
16
|
+
its(:name) { should == application_name }
|
17
|
+
|
18
|
+
context "but the application id is invalid" do
|
19
|
+
let(:application_id) { - 1}
|
20
|
+
|
21
|
+
it "raises an error" do
|
22
|
+
expect { subject }.to raise_error(Jirafe::Error::ResourceNotFound)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when the token is the reporting token" do
|
28
|
+
before { use_reporting_token }
|
29
|
+
let(:cassette) { "application_get_with_reporting_token" }
|
30
|
+
|
31
|
+
its(:class) { should == Jirafe::Resource::Application }
|
32
|
+
its(:identifier) { should == application_id }
|
33
|
+
its(:name) { should == application_name }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when the token is the cloud token" do
|
37
|
+
before { use_cloud_token }
|
38
|
+
let(:cassette) { "application_get_with_cloud_token" }
|
39
|
+
|
40
|
+
it "raises an error" do
|
41
|
+
expect { subject }.to raise_error(Jirafe::Error::Forbidden)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when the token is an invalid token" do
|
46
|
+
before { use_invalid_token }
|
47
|
+
let(:cassette) { "application_get_with_invalid_token" }
|
48
|
+
|
49
|
+
it "raises an error" do
|
50
|
+
expect { subject }.to raise_error(Jirafe::Error::Unauthorized)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".create" do
|
56
|
+
subject { make_request(cassette) { resource.create } }
|
57
|
+
|
58
|
+
context "when the token is the master token" do
|
59
|
+
before { use_master_token }
|
60
|
+
|
61
|
+
context "and the resource is new" do
|
62
|
+
let(:cassette) { "application_post_with_master_token" }
|
63
|
+
let(:resource) { Jirafe::Resource::Application.new(:name => "my new app") }
|
64
|
+
|
65
|
+
its(:class) { should == Jirafe::Resource::Application }
|
66
|
+
its(:identifier) { should be_nonzero }
|
67
|
+
its(:name) { should == "my new app" }
|
68
|
+
its(:app_id) { should_not be_nil }
|
69
|
+
its(:token) { should_not be_nil }
|
70
|
+
|
71
|
+
context "with a duplicate name" do
|
72
|
+
before { resource.name = application_name }
|
73
|
+
let(:cassette) { "application_post_with_master_token_dupe_name" }
|
74
|
+
|
75
|
+
its(:name) { should == application_name }
|
76
|
+
end
|
77
|
+
|
78
|
+
context "with a blank name" do
|
79
|
+
before { resource.name = "" }
|
80
|
+
let(:cassette) { "application_post_with_master_token_blank_name" }
|
81
|
+
|
82
|
+
it "raises an error" do
|
83
|
+
expect { subject }.to raise_error(Jirafe::Error::BadRequest)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "with no name" do
|
88
|
+
before { resource.name = nil }
|
89
|
+
let(:cassette) { "application_post_with_master_token_no_name" }
|
90
|
+
|
91
|
+
it "raises an error" do
|
92
|
+
expect { subject }.to raise_error(Jirafe::Error::BadRequest)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "when the token is the report token" do
|
99
|
+
before { use_reporting_token }
|
100
|
+
|
101
|
+
context "and the resource is new" do
|
102
|
+
let(:cassette) { "application_post_with_reporting_token" }
|
103
|
+
let(:resource) { Jirafe::Resource::Application.new(:name => "my new app") }
|
104
|
+
|
105
|
+
its(:identifier) { should be_nonzero }
|
106
|
+
its(:name) { should == "my new app" }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "when the token is the cloud token" do
|
111
|
+
before { use_reporting_token }
|
112
|
+
|
113
|
+
context "and the resource is new" do
|
114
|
+
let(:cassette) { "application_post_with_cloud_token" }
|
115
|
+
let(:resource) { Jirafe::Resource::Application.new(:name => "my new app") }
|
116
|
+
|
117
|
+
its(:identifier) { should be_nonzero }
|
118
|
+
its(:name) { should == "my new app" }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when the token is an invalid token" do
|
123
|
+
before { use_invalid_token }
|
124
|
+
|
125
|
+
context "and the resource is new" do
|
126
|
+
let(:cassette) { "application_post_with_invalid_token" }
|
127
|
+
let(:resource) { Jirafe::Resource::Application.new(:name => "my new app") }
|
128
|
+
|
129
|
+
it "raises an error" do
|
130
|
+
expect { subject }.to raise_error(Jirafe::Error::Unauthorized)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "and the resource already exists" do
|
135
|
+
let(:cassette) { "application_put_with_invalid_token" }
|
136
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
137
|
+
|
138
|
+
it "raises an error" do
|
139
|
+
expect { subject }.to raise_error(Jirafe::Error::Unauthorized)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe ".update" do
|
146
|
+
subject { make_request(cassette) { resource.update } }
|
147
|
+
|
148
|
+
context "when the token is the master token" do
|
149
|
+
before { use_master_token }
|
150
|
+
|
151
|
+
context "and the resource already exists" do
|
152
|
+
let(:cassette) { "application_put_with_master_token" }
|
153
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
154
|
+
|
155
|
+
it "raises an error" do
|
156
|
+
expect { subject }.to raise_error(Jirafe::Error::Forbidden)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when the token is the report token" do
|
162
|
+
before { use_reporting_token }
|
163
|
+
|
164
|
+
context "and the resource already exists" do
|
165
|
+
let(:cassette) { "application_put_with_reporting_token" }
|
166
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
167
|
+
|
168
|
+
it "raises an error" do
|
169
|
+
expect { subject }.to raise_error(Jirafe::Error::Forbidden)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "when the token is the cloud token" do
|
175
|
+
before { use_reporting_token }
|
176
|
+
|
177
|
+
context "and the resource already exists" do
|
178
|
+
let(:cassette) { "application_put_with_cloud_token" }
|
179
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
180
|
+
|
181
|
+
it "raises an error" do
|
182
|
+
expect { subject }.to raise_error(Jirafe::Error::Forbidden)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "when the token is an invalid token" do
|
188
|
+
before { use_invalid_token }
|
189
|
+
|
190
|
+
context "and the resource is new" do
|
191
|
+
let(:cassette) { "application_put_with_invalid_token" }
|
192
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
193
|
+
|
194
|
+
it "raises an error" do
|
195
|
+
expect { subject }.to raise_error(Jirafe::Error::Unauthorized)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "and the resource already exists" do
|
200
|
+
let(:cassette) { "application_put_with_invalid_token" }
|
201
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
202
|
+
|
203
|
+
it "raises an error" do
|
204
|
+
expect { subject }.to raise_error(Jirafe::Error::Unauthorized)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "#sites" do
|
211
|
+
subject { make_request(cassette) { resource.sites } }
|
212
|
+
let(:resource) { Jirafe::Resource::Application.new(:identifier => application_id, :name => "my new app") }
|
213
|
+
|
214
|
+
let(:cassette) { "application_sites_get_with_master_token" }
|
215
|
+
|
216
|
+
its(:class) { should == Array }
|
217
|
+
its(:size) { should == 1 }
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jirafe::Resource::JirafeResource do
|
4
|
+
let(:resource_class) { Jirafe::Resource::JirafeResource }
|
5
|
+
before do
|
6
|
+
class TestResourceClass < Jirafe::Resource::JirafeResource
|
7
|
+
end
|
8
|
+
class ParentResourceClass < Jirafe::Resource::JirafeResource
|
9
|
+
path "parent"
|
10
|
+
attributes({:identifier => [:identifier]})
|
11
|
+
end
|
12
|
+
class ChildResourceClass < Jirafe::Resource::JirafeResource
|
13
|
+
path "child"
|
14
|
+
parent ParentResourceClass
|
15
|
+
attributes({:identifier => [:identifier]})
|
16
|
+
end
|
17
|
+
class GrandChildResourceClass < Jirafe::Resource::JirafeResource
|
18
|
+
path "grandchild"
|
19
|
+
parent ChildResourceClass
|
20
|
+
attributes({:identifier => [:identifier]})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".path" do
|
25
|
+
subject { resource_class.path(path) }
|
26
|
+
after { resource_class.instance_variable_set("@path", nil) }
|
27
|
+
|
28
|
+
context "when given a path" do
|
29
|
+
let(:path) { "mypath" }
|
30
|
+
|
31
|
+
context "and the base resource class" do
|
32
|
+
it { should == Jirafe.config.url }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "and given a subclass" do
|
36
|
+
let(:resource_class) { TestResourceClass }
|
37
|
+
|
38
|
+
it { should == "mypath" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "given no path" do
|
43
|
+
let(:path) { nil }
|
44
|
+
context "and it is not already set" do
|
45
|
+
context "and the base resource class" do
|
46
|
+
it { should == Jirafe.config.url }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and given a subclass" do
|
50
|
+
let(:resource_class) { TestResourceClass }
|
51
|
+
|
52
|
+
it "raises an error" do
|
53
|
+
expect { subject }.to raise_error(Jirafe::Error::MissingResourcePath)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "and it is already set" do
|
59
|
+
context "and the base resource class" do
|
60
|
+
it { should == Jirafe.config.url }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "and given a subclass" do
|
64
|
+
let(:resource_class) { TestResourceClass }
|
65
|
+
|
66
|
+
it "returns the path" do
|
67
|
+
resource_class.path("newpath")
|
68
|
+
resource_class.path.should == "newpath"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe ".parent" do
|
76
|
+
subject { resource_class.parent(parent) }
|
77
|
+
after { resource_class.instance_variable_set("@parent", nil) }
|
78
|
+
|
79
|
+
context "when given a parent" do
|
80
|
+
let(:parent) { "parent" }
|
81
|
+
|
82
|
+
context "and given a subclass" do
|
83
|
+
let(:resource_class) { TestResourceClass }
|
84
|
+
|
85
|
+
it { should == "parent" }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "given no parent" do
|
90
|
+
let(:parent) { nil }
|
91
|
+
context "and given a subclass" do
|
92
|
+
let(:resource_class) { TestResourceClass }
|
93
|
+
it { should == resource_class.superclass }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#parent" do
|
99
|
+
subject { resource_class.new.parent }
|
100
|
+
|
101
|
+
context "given the base resource class" do
|
102
|
+
it { should be_nil }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "#resource_url" do
|
107
|
+
subject { resource.resource_url }
|
108
|
+
let(:resource) { resource_class.new }
|
109
|
+
let(:base_url) { Jirafe.config.url }
|
110
|
+
|
111
|
+
context "given the base resource class" do
|
112
|
+
it { should == base_url }
|
113
|
+
end
|
114
|
+
|
115
|
+
context "given a subclass" do
|
116
|
+
let(:resource_class) { ParentResourceClass }
|
117
|
+
|
118
|
+
context "with no identifier" do
|
119
|
+
it { should == "#{base_url}/parent"}
|
120
|
+
end
|
121
|
+
|
122
|
+
context "with an identifier" do
|
123
|
+
let(:resource) { resource_class.new(:identifier => 1) }
|
124
|
+
|
125
|
+
it { should == "#{base_url}/parent/1"}
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "given a child subclass" do
|
130
|
+
let(:resource_class) { ChildResourceClass }
|
131
|
+
|
132
|
+
context "with a parent identifier" do
|
133
|
+
let(:parent_resource) { ParentResourceClass.new(:identifier => 1) }
|
134
|
+
let(:resource) { resource_class.new(:parent => parent_resource) }
|
135
|
+
it { should == "#{base_url}/parent/1/child"}
|
136
|
+
|
137
|
+
context "with an identifier" do
|
138
|
+
let(:resource) { resource_class.new(:parent => parent_resource, :identifier => 2) }
|
139
|
+
it { should == "#{base_url}/parent/1/child/2"}
|
140
|
+
|
141
|
+
context "and deeply nested" do
|
142
|
+
let(:resource) do
|
143
|
+
GrandChildResourceClass.new(
|
144
|
+
:parent => ChildResourceClass.new(
|
145
|
+
:parent => ParentResourceClass.new(
|
146
|
+
:identifier => 1),
|
147
|
+
:identifier => 2),
|
148
|
+
:identifier => 3)
|
149
|
+
end
|
150
|
+
|
151
|
+
it { should == "#{base_url}/parent/1/child/2/grandchild/3"}
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
describe ".get" do
|
160
|
+
subject { make_request(cassette) { resource_class.get(url).parsed_response } }
|
161
|
+
|
162
|
+
context "given a url" do
|
163
|
+
let(:url) { "/status" }
|
164
|
+
let(:cassette) { "jirafe_resource_get_status_url" }
|
165
|
+
|
166
|
+
it { should == {"status" => "ok"} }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe ".retrieve" do
|
171
|
+
subject { make_request(cassette) { resource_class.retrieve } }
|
172
|
+
let(:cassette) { "jirafe_resource_get_status_url" }
|
173
|
+
let(:resource_class) { Jirafe::Resource::Status }
|
174
|
+
|
175
|
+
its(:class) { should == resource_class }
|
176
|
+
its(:status) { should == "ok" }
|
177
|
+
|
178
|
+
context "with an option" do
|
179
|
+
subject { make_request(cassette) { resource_class.retrieve(nil, {:query_param => true}) } }
|
180
|
+
let(:cassette) { "jirafe_resource_get_status_url_with_query_param" }
|
181
|
+
let(:resource_class) { Jirafe::Resource::Status }
|
182
|
+
|
183
|
+
its(:class) { should == resource_class }
|
184
|
+
its(:status) { should == "ok" }
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jirafe::Resource::Site do
|
4
|
+
let(:resource_class) { Jirafe::Resource::Site }
|
5
|
+
let(:application_id) { 1 }
|
6
|
+
let(:site_id) { 1 }
|
7
|
+
let(:site_description) { "Test Site" }
|
8
|
+
let(:site_url) { "http://jirafe.com" }
|
9
|
+
let(:site_timezone) { "Europe/Paris" }
|
10
|
+
let(:site_currency) { "EUR" }
|
11
|
+
|
12
|
+
describe ".retrieve" do
|
13
|
+
subject { make_request(cassette) { resource_class.retrieve(site_id, application_id) } }
|
14
|
+
|
15
|
+
let(:cassette) { "site_get_with_master_token" }
|
16
|
+
|
17
|
+
its(:class) { should == resource_class }
|
18
|
+
its(:identifier) { should == site_id }
|
19
|
+
its(:description) { should == site_description }
|
20
|
+
its(:url) { should == site_url }
|
21
|
+
its(:timezone) { should == site_timezone }
|
22
|
+
its(:currency) { should == site_currency }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".list" do
|
26
|
+
subject { make_request(cassette) { resource_class.list(application_id) } }
|
27
|
+
let(:cassette) { "site_get_with_master_token" }
|
28
|
+
|
29
|
+
its(:class) { should == Array }
|
30
|
+
its(:size) { should == 1 }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".create" do
|
34
|
+
subject { make_request(cassette) { resource.create } }
|
35
|
+
let(:app) { Jirafe::Resource::Application.new(:name => "my new app") }
|
36
|
+
|
37
|
+
context "when the token is the app token" do
|
38
|
+
before do
|
39
|
+
use_master_token
|
40
|
+
make_request "application_post_with_master_token" do
|
41
|
+
app.create
|
42
|
+
end
|
43
|
+
resource.app_id = app.identifier
|
44
|
+
resource.parent = app
|
45
|
+
|
46
|
+
use_app_token(app)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "and the resource is new" do
|
50
|
+
let(:cassette) { "site_post_with_app_token" }
|
51
|
+
let(:resource) { Jirafe::Resource::Site.new(:description => "my new site", :url => "http://example.com/") }
|
52
|
+
|
53
|
+
its(:class) { should == Jirafe::Resource::Site }
|
54
|
+
its(:identifier) { should be_nonzero }
|
55
|
+
its(:description) { should == "my new site" }
|
56
|
+
its(:url) { should == "http://example.com/" }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|