spree_api 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/stores_controller.rb +55 -0
- data/app/helpers/spree/api/api_helpers.rb +9 -2
- data/app/views/spree/api/stores/index.v1.rabl +4 -0
- data/app/views/spree/api/stores/show.v1.rabl +2 -0
- data/config/routes.rb +2 -0
- data/spec/controllers/spree/api/stores_controller_spec.rb +133 -0
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3736aa7fa433082c6e7771f2e1850ff8f7e14a76
|
4
|
+
data.tar.gz: 51e229c7ed5a6d30f00ad17aa48ec58d8dc8a5b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d188802236b8f7c836f98df8183b028dc4de465080f0382b5119f1017bf11dd1735b43b9048773f10aea96bb95f3474ce86c93f12a736ccbb0068e597d47e2
|
7
|
+
data.tar.gz: a2e7952731ee46c9896bc562d74926abeb370a80adb8f58f446a8ebfdd7d5d4dd9300e60eda4e536c22db35f844126c0921f716a5b83e0d76594c0b97d1ce165
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
class StoresController < Spree::Api::BaseController
|
4
|
+
|
5
|
+
before_filter :get_store, except: [:index, :create]
|
6
|
+
|
7
|
+
def index
|
8
|
+
authorize! :read, Store
|
9
|
+
@stores = Store.accessible_by(current_ability, :read).all
|
10
|
+
respond_with(@stores)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
authorize! :create, Store
|
15
|
+
@store = Store.new(store_params)
|
16
|
+
@store.code = params[:store][:code]
|
17
|
+
if @store.save
|
18
|
+
respond_with(@store, status: 201, default_template: :show)
|
19
|
+
else
|
20
|
+
invalid_resource!(@store)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
authorize! :update, @store
|
26
|
+
if @store.update_attributes(store_params)
|
27
|
+
respond_with(@store, status: 200, default_template: :show)
|
28
|
+
else
|
29
|
+
invalid_resource!(@store)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
authorize! :read, @store
|
35
|
+
respond_with(@store)
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
authorize! :destroy, @store
|
40
|
+
@store.destroy
|
41
|
+
respond_with(@store, status: 204)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def get_store
|
47
|
+
@store = Store.find(params[:id])
|
48
|
+
end
|
49
|
+
|
50
|
+
def store_params
|
51
|
+
params.require(:store).permit(permitted_store_attributes)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -28,7 +28,8 @@ module Spree
|
|
28
28
|
:stock_location_attributes,
|
29
29
|
:stock_movement_attributes,
|
30
30
|
:stock_item_attributes,
|
31
|
-
:promotion_attributes
|
31
|
+
:promotion_attributes,
|
32
|
+
:store_attributes
|
32
33
|
]
|
33
34
|
|
34
35
|
mattr_reader *ATTRIBUTES
|
@@ -150,7 +151,13 @@ module Spree
|
|
150
151
|
]
|
151
152
|
|
152
153
|
@@promotion_attributes = [
|
153
|
-
|
154
|
+
:id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
|
155
|
+
:match_policy, :code, :advertise, :path
|
156
|
+
]
|
157
|
+
|
158
|
+
@@store_attributes = [
|
159
|
+
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
|
160
|
+
:mail_from_address, :default_currency, :code, :default
|
154
161
|
]
|
155
162
|
|
156
163
|
def variant_attributes
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,133 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Api::StoresController, type: :controller do
|
5
|
+
render_views
|
6
|
+
|
7
|
+
let!(:store) do
|
8
|
+
create(:store, name: "My Spree Store", url: "spreestore.example.com")
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
stub_authentication!
|
13
|
+
end
|
14
|
+
|
15
|
+
context "as an admin" do
|
16
|
+
sign_in_as_admin!
|
17
|
+
|
18
|
+
let!(:non_default_store) do
|
19
|
+
create(:store,
|
20
|
+
name: "Extra Store",
|
21
|
+
url: "spreestore-5.example.com",
|
22
|
+
default: false
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "I can list the available stores" do
|
27
|
+
api_get :index
|
28
|
+
expect(json_response["stores"]).to eq([
|
29
|
+
{
|
30
|
+
"id" => store.id,
|
31
|
+
"name" => "My Spree Store",
|
32
|
+
"url" => "spreestore.example.com",
|
33
|
+
"meta_description" => nil,
|
34
|
+
"meta_keywords" => nil,
|
35
|
+
"seo_title" => nil,
|
36
|
+
"mail_from_address" => "spree@example.org",
|
37
|
+
"default_currency" => nil,
|
38
|
+
"code" => "spree_1",
|
39
|
+
"default" => true
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"id" => non_default_store.id,
|
43
|
+
"name" => "Extra Store",
|
44
|
+
"url" => "spreestore-5.example.com",
|
45
|
+
"meta_description" => nil,
|
46
|
+
"meta_keywords" => nil,
|
47
|
+
"seo_title" => nil,
|
48
|
+
"mail_from_address" => "spree@example.org",
|
49
|
+
"default_currency" => nil,
|
50
|
+
"code" => "spree_2",
|
51
|
+
"default" => false
|
52
|
+
}
|
53
|
+
])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "I can get the store details" do
|
57
|
+
api_get :show, id: store.id
|
58
|
+
expect(json_response).to eq(
|
59
|
+
"id" => store.id,
|
60
|
+
"name" => "My Spree Store",
|
61
|
+
"url" => "spreestore.example.com",
|
62
|
+
"meta_description" => nil,
|
63
|
+
"meta_keywords" => nil,
|
64
|
+
"seo_title" => nil,
|
65
|
+
"mail_from_address" => "spree@example.org",
|
66
|
+
"default_currency" => nil,
|
67
|
+
"code" => store.code,
|
68
|
+
"default" => true
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "I can create a new store" do
|
73
|
+
store_hash = {
|
74
|
+
code: "spree123",
|
75
|
+
name: "Hack0rz",
|
76
|
+
url: "spree123.example.com",
|
77
|
+
mail_from_address: "me@example.com"
|
78
|
+
}
|
79
|
+
api_post :create, store: store_hash
|
80
|
+
expect(response.status).to eq(201)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "I can update an existing store" do
|
84
|
+
store_hash = {
|
85
|
+
url: "spree123.example.com",
|
86
|
+
mail_from_address: "me@example.com"
|
87
|
+
}
|
88
|
+
api_put :update, id: store.id, store: store_hash
|
89
|
+
expect(response.status).to eq(200)
|
90
|
+
expect(store.reload.url).to eql "spree123.example.com"
|
91
|
+
expect(store.reload.mail_from_address).to eql "me@example.com"
|
92
|
+
end
|
93
|
+
|
94
|
+
context "deleting a store" do
|
95
|
+
it "will fail if it's the default Store" do
|
96
|
+
api_delete :destroy, id: store.id
|
97
|
+
expect(response.status).to eq(422)
|
98
|
+
expect(json_response["errors"]["base"]).to eql(
|
99
|
+
["Cannot destroy the default Store."]
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "will destroy the store" do
|
104
|
+
api_delete :destroy, id: non_default_store.id
|
105
|
+
expect(response.status).to eq(204)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "as an user" do
|
111
|
+
|
112
|
+
it "I cannot list all the stores" do
|
113
|
+
api_get :index
|
114
|
+
expect(response.status).to eq(401)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "I cannot get the store details" do
|
118
|
+
api_get :show, id: store.id
|
119
|
+
expect(response.status).to eq(401)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "I cannot create a new store" do
|
123
|
+
api_post :create, store: {}
|
124
|
+
expect(response.status).to eq(401)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "I cannot update an existing store" do
|
128
|
+
api_put :update, id: store.id, store: {}
|
129
|
+
expect(response.status).to eq(401)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.4.
|
19
|
+
version: 2.4.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.4.
|
26
|
+
version: 2.4.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- app/controllers/spree/api/stock_items_controller.rb
|
89
89
|
- app/controllers/spree/api/stock_locations_controller.rb
|
90
90
|
- app/controllers/spree/api/stock_movements_controller.rb
|
91
|
+
- app/controllers/spree/api/stores_controller.rb
|
91
92
|
- app/controllers/spree/api/taxonomies_controller.rb
|
92
93
|
- app/controllers/spree/api/taxons_controller.rb
|
93
94
|
- app/controllers/spree/api/users_controller.rb
|
@@ -166,6 +167,8 @@ files:
|
|
166
167
|
- app/views/spree/api/stock_locations/show.v1.rabl
|
167
168
|
- app/views/spree/api/stock_movements/index.v1.rabl
|
168
169
|
- app/views/spree/api/stock_movements/show.v1.rabl
|
170
|
+
- app/views/spree/api/stores/index.v1.rabl
|
171
|
+
- app/views/spree/api/stores/show.v1.rabl
|
169
172
|
- app/views/spree/api/taxonomies/index.v1.rabl
|
170
173
|
- app/views/spree/api/taxonomies/jstree.rabl
|
171
174
|
- app/views/spree/api/taxonomies/nested.v1.rabl
|
@@ -228,6 +231,7 @@ files:
|
|
228
231
|
- spec/controllers/spree/api/stock_items_controller_spec.rb
|
229
232
|
- spec/controllers/spree/api/stock_locations_controller_spec.rb
|
230
233
|
- spec/controllers/spree/api/stock_movements_controller_spec.rb
|
234
|
+
- spec/controllers/spree/api/stores_controller_spec.rb
|
231
235
|
- spec/controllers/spree/api/taxonomies_controller_spec.rb
|
232
236
|
- spec/controllers/spree/api/taxons_controller_spec.rb
|
233
237
|
- spec/controllers/spree/api/unauthenticated_products_controller_spec.rb
|
@@ -292,6 +296,7 @@ test_files:
|
|
292
296
|
- spec/controllers/spree/api/stock_items_controller_spec.rb
|
293
297
|
- spec/controllers/spree/api/stock_locations_controller_spec.rb
|
294
298
|
- spec/controllers/spree/api/stock_movements_controller_spec.rb
|
299
|
+
- spec/controllers/spree/api/stores_controller_spec.rb
|
295
300
|
- spec/controllers/spree/api/taxonomies_controller_spec.rb
|
296
301
|
- spec/controllers/spree/api/taxons_controller_spec.rb
|
297
302
|
- spec/controllers/spree/api/unauthenticated_products_controller_spec.rb
|