solidus_api 1.1.0.pre1 → 1.1.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/address_books_controller.rb +31 -10
- data/app/controllers/spree/api/line_items_controller.rb +1 -2
- data/app/controllers/spree/api/users_controller.rb +5 -1
- data/app/views/spree/api/address_books/show.v1.rabl +4 -1
- data/app/views/spree/api/shipments/big.v1.rabl +7 -0
- data/app/views/spree/api/variants/big.v1.rabl +1 -1
- data/app/views/spree/api/variants/small.v1.rabl +1 -1
- data/config/routes.rb +1 -2
- data/spec/controllers/spree/api/orders_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/shipments_controller_spec.rb +19 -0
- data/spec/controllers/spree/api/stock_transfers_controller_spec.rb +15 -0
- data/spec/requests/api/address_books_spec.rb +222 -0
- metadata +6 -6
- data/spec/controllers/spree/api/address_books_controller_spec.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fec876f748a73c00b4d7dbf63c2d3270a719ce7
|
4
|
+
data.tar.gz: b63a3f8f6ea3b237dd49057a787b9a2bd0e22afd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f89a236ed244de294c74ac119ce8ff13baf8f657e049d55ca8b32946ffb75b644b25ade0ae7a0e68f9d1233daa61e3e343788683d124af2212c74b6fbad8e84
|
7
|
+
data.tar.gz: d5637fc1f6611d61aeb4e517628da33db9b4335fe95e77e19738ff21cf4d5fe7387f16ccce6c6ecd56f6162f486e8bd293864ea8e7d749084f9425d479217b3a
|
@@ -2,32 +2,53 @@ module Spree
|
|
2
2
|
module Api
|
3
3
|
class AddressBooksController < Spree::Api::BaseController
|
4
4
|
# Note: the AddressBook is the resource to think about here, not individual addresses
|
5
|
+
before_filter :load_user_addresses
|
5
6
|
|
6
7
|
def show
|
7
|
-
|
8
|
+
authorize! :show, address_book_user
|
9
|
+
|
10
|
+
render :show, status: :ok
|
8
11
|
end
|
9
12
|
|
13
|
+
# Update a user's address book by adding an address to it or by updating
|
14
|
+
# the associated UserAddress (e.g. making it the default).
|
15
|
+
#
|
16
|
+
# @param user_id [String] the user id of the address book we're updating.
|
17
|
+
# @param address_book [Hash] any key-values permitted by
|
18
|
+
# permitted_address_book_attributes
|
19
|
+
# @return [Array] *All* of the user's addresses, since the resource here
|
20
|
+
# is the address book and since we may have mutated other UserAddresses
|
21
|
+
# (e.g. changed the 'default' flag). The user's default address will be
|
22
|
+
# flagged with default=true and the target address from this update will
|
23
|
+
# be flagged with update_target=true.
|
10
24
|
def update
|
25
|
+
authorize! :save_in_address_book, address_book_user
|
26
|
+
|
11
27
|
address_params = address_book_params
|
12
28
|
default_flag = address_params.delete(:default)
|
13
|
-
address =
|
14
|
-
if address.valid?
|
15
|
-
|
29
|
+
@address = address_book_user.save_in_address_book(address_params, default_flag)
|
30
|
+
if @address.valid?
|
31
|
+
render :show, status: :ok
|
16
32
|
else
|
17
|
-
invalid_resource!(address)
|
33
|
+
invalid_resource!(@address)
|
18
34
|
end
|
19
35
|
end
|
20
36
|
|
21
37
|
def destroy
|
22
|
-
|
23
|
-
|
38
|
+
authorize! :remove_from_address_book, address_book_user
|
39
|
+
|
40
|
+
address_book_user.remove_from_address_book(params[:address_id])
|
41
|
+
render :show, status: :ok
|
24
42
|
end
|
25
43
|
|
26
44
|
private
|
27
45
|
|
28
|
-
def
|
29
|
-
@
|
30
|
-
|
46
|
+
def address_book_user
|
47
|
+
@address_book_user ||= Spree.user_class.find(params[:user_id])
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_user_addresses
|
51
|
+
@user_addresses ||= address_book_user.user_addresses
|
31
52
|
end
|
32
53
|
|
33
54
|
def address_book_params
|
@@ -37,8 +37,7 @@ module Spree
|
|
37
37
|
|
38
38
|
def destroy
|
39
39
|
@line_item = find_line_item
|
40
|
-
|
41
|
-
@order.contents.remove(variant, @line_item.quantity)
|
40
|
+
@order.contents.remove_line_item(@line_item)
|
42
41
|
respond_with(@line_item, status: 204)
|
43
42
|
end
|
44
43
|
|
@@ -15,6 +15,10 @@ class Spree::Api::UsersController < Spree::Api::ResourceController
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def permitted_resource_attributes
|
18
|
-
|
18
|
+
if action_name == "create" || can?(:update_email, user)
|
19
|
+
super | [:email]
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
collection @user_addresses
|
2
2
|
node do |user_address|
|
3
|
-
partial("spree/api/addresses/show", object: user_address.address).merge(
|
3
|
+
partial("spree/api/addresses/show", object: user_address.address).merge(
|
4
|
+
default: user_address.default,
|
5
|
+
update_target: @address == user_address.address,
|
6
|
+
)
|
4
7
|
end
|
@@ -41,6 +41,13 @@ child order: :order do
|
|
41
41
|
|
42
42
|
child payments: :payments do
|
43
43
|
attributes :id, :amount, :display_amount, :state
|
44
|
+
child source: :source do |s|
|
45
|
+
attrs = [:id]
|
46
|
+
if s.respond_to?(:cc_type)
|
47
|
+
attrs << :cc_type
|
48
|
+
end
|
49
|
+
attributes *attrs
|
50
|
+
end
|
44
51
|
child payment_method: :payment_method do
|
45
52
|
attributes :id, :name
|
46
53
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
object @variant
|
2
2
|
attributes *variant_attributes
|
3
3
|
|
4
|
-
cache [I18n.locale,
|
4
|
+
cache [I18n.locale, Spree::StockLocation.accessible_by(current_ability).pluck(:id).sort.join(":"), 'big_variant', root_object]
|
5
5
|
|
6
6
|
extends "spree/api/variants/small"
|
7
7
|
|
data/config/routes.rb
CHANGED
@@ -107,6 +107,7 @@ Spree::Core::Engine.add_routes do
|
|
107
107
|
|
108
108
|
resources :users do
|
109
109
|
resources :credit_cards, only: [:index]
|
110
|
+
resource :address_book, only: [:show, :update, :destroy]
|
110
111
|
end
|
111
112
|
|
112
113
|
resources :credit_cards, only: [:update]
|
@@ -134,8 +135,6 @@ Spree::Core::Engine.add_routes do
|
|
134
135
|
end
|
135
136
|
end
|
136
137
|
|
137
|
-
resource :address_book, only: [:show, :update, :destroy]
|
138
|
-
|
139
138
|
get '/config/money', to: 'config#money'
|
140
139
|
get '/config', to: 'config#show'
|
141
140
|
put '/classifications', to: 'classifications#update', as: :classifications
|
@@ -226,7 +226,7 @@ module Spree
|
|
226
226
|
|
227
227
|
describe 'GET #show' do
|
228
228
|
let(:order) { create :order_with_line_items }
|
229
|
-
let(:adjustment) { FactoryGirl.create(:adjustment, order: order) }
|
229
|
+
let(:adjustment) { FactoryGirl.create(:adjustment, adjustable: order, order: order) }
|
230
230
|
|
231
231
|
subject { api_get :show, id: order.to_param }
|
232
232
|
|
@@ -162,6 +162,25 @@ describe Spree::Api::ShipmentsController, :type => :controller do
|
|
162
162
|
subject
|
163
163
|
expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)
|
164
164
|
end
|
165
|
+
|
166
|
+
context "credit card payment" do
|
167
|
+
before { subject }
|
168
|
+
|
169
|
+
it 'contains the id and cc_type of the credit card' do
|
170
|
+
expect(json_response['shipments'][0]['order']['payments'][0]['source'].keys).to match_array ["id", "cc_type"]
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "store credit payment" do
|
175
|
+
let(:current_api_user) { shipped_order.user }
|
176
|
+
let(:shipped_order) { create(:shipped_order, payment_type: :store_credit_payment) }
|
177
|
+
|
178
|
+
before { subject }
|
179
|
+
|
180
|
+
it 'only contains the id of the payment source' do
|
181
|
+
expect(json_response['shipments'][0]['order']['payments'][0]['source'].keys).to match_array ["id"]
|
182
|
+
end
|
183
|
+
end
|
165
184
|
end
|
166
185
|
|
167
186
|
context 'with filtering' do
|
@@ -46,6 +46,21 @@ module Spree
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
context "transfer item does not have stock in source location after ship" do
|
50
|
+
let(:variant_id) { transfer_item.variant.to_param }
|
51
|
+
let(:user) { create :user }
|
52
|
+
|
53
|
+
before do
|
54
|
+
stock_transfer.finalize(user)
|
55
|
+
stock_transfer.ship(shipped_at: Time.now)
|
56
|
+
stock_transfer.source_location.stock_item(transfer_item.variant_id).set_count_on_hand(0)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can still receive item" do
|
60
|
+
expect { subject }.to change { transfer_item.reload.received_quantity }.by(1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
49
64
|
context "transfer item has been fully received" do
|
50
65
|
let(:variant_id) { transfer_item.variant.to_param }
|
51
66
|
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Api::AddressBooksController, :type => :request do
|
5
|
+
let!(:state) { create(:state) }
|
6
|
+
let!(:harry_address_attributes) do
|
7
|
+
{
|
8
|
+
'firstname' => 'Harry',
|
9
|
+
'lastname' => 'Potter',
|
10
|
+
'address1' => '4 Privet Drive',
|
11
|
+
'address2' => 'cupboard under the stairs',
|
12
|
+
'city' => 'Surrey',
|
13
|
+
'zipcode' => '10010',
|
14
|
+
'phone' => '555-5555',
|
15
|
+
'state_id' => state.id,
|
16
|
+
'country_id' => state.country.id
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let!(:ron_address_attributes) do
|
21
|
+
{
|
22
|
+
'firstname' => 'Ron',
|
23
|
+
'lastname' => 'Weasly',
|
24
|
+
'address1' => 'Ottery St. Catchpole',
|
25
|
+
'address2' => '4th floor',
|
26
|
+
'city' => 'Devon, West Country',
|
27
|
+
'zipcode' => '10010',
|
28
|
+
'phone' => '555-5555',
|
29
|
+
'state_id' => state.id,
|
30
|
+
'country_id' => state.country.id
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'as address book owner' do
|
35
|
+
context 'with ability' do
|
36
|
+
it 'returns my address book' do
|
37
|
+
user = create(:user, spree_api_key: 'galleon')
|
38
|
+
user.save_in_address_book(harry_address_attributes, true)
|
39
|
+
user.save_in_address_book(ron_address_attributes, false)
|
40
|
+
|
41
|
+
get "/api/users/#{user.id}/address_book", nil, { 'X-SPREE-TOKEN' => 'galleon'}
|
42
|
+
|
43
|
+
json_response = JSON.parse(response.body)
|
44
|
+
expect(response.status).to eq(200)
|
45
|
+
expect(json_response.length).to eq(2)
|
46
|
+
expect(json_response).to include(
|
47
|
+
hash_including(harry_address_attributes.merge!('default' => true)),
|
48
|
+
hash_including(ron_address_attributes.merge!('default' => false)),
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'updates my address book' do
|
53
|
+
user = create(:user, spree_api_key: 'galleon')
|
54
|
+
address = user.save_in_address_book(harry_address_attributes, true)
|
55
|
+
harry_address_attributes['firstname'] = 'Ron'
|
56
|
+
|
57
|
+
expect {
|
58
|
+
put "/api/users/#{user.id}/address_book", { address_book: harry_address_attributes.merge('id' => address.id) }, { 'X-SPREE-TOKEN' => 'galleon' }
|
59
|
+
}.to change { UserAddress.count }.from(1).to(2)
|
60
|
+
|
61
|
+
expect(response.status).to eq(200)
|
62
|
+
expect(JSON.parse(response.body).first).to include(harry_address_attributes)
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when creating an address' do
|
66
|
+
it 'marks the update_target' do
|
67
|
+
user = create(:user, spree_api_key: 'galleon')
|
68
|
+
|
69
|
+
expect {
|
70
|
+
put "/api/users/#{user.id}/address_book", { address_book: harry_address_attributes }, { 'X-SPREE-TOKEN' => 'galleon' }
|
71
|
+
}.to change { UserAddress.count }.by(1)
|
72
|
+
|
73
|
+
user_address = UserAddress.last
|
74
|
+
|
75
|
+
expect(response.status).to eq(200)
|
76
|
+
update_target_ids = JSON.parse(response.body).select { |a| a['update_target'] }.map { |a| a['id'] }
|
77
|
+
expect(update_target_ids).to eq([user_address.address_id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when updating an address' do
|
82
|
+
it 'marks the update_target' do
|
83
|
+
user = create(:user, spree_api_key: 'galleon')
|
84
|
+
address = user.save_in_address_book(harry_address_attributes, true)
|
85
|
+
|
86
|
+
expect {
|
87
|
+
put "/api/users/#{user.id}/address_book", { address_book: harry_address_attributes }, { 'X-SPREE-TOKEN' => 'galleon' }
|
88
|
+
}.to_not change { UserAddress.count }
|
89
|
+
|
90
|
+
expect(response.status).to eq(200)
|
91
|
+
update_target_ids = JSON.parse(response.body).select { |a| a['update_target'] }.map { |a| a['id'] }
|
92
|
+
expect(update_target_ids).to eq([address.id])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'archives my address' do
|
97
|
+
address = create(:address)
|
98
|
+
user = create(:user, spree_api_key: 'galleon')
|
99
|
+
user.save_in_address_book(address.attributes, false)
|
100
|
+
|
101
|
+
expect {
|
102
|
+
delete "/api/users/#{user.id}/address_book", { address_id: address.id }, { 'X-SPREE-TOKEN' => 'galleon'}
|
103
|
+
}.to change { user.reload.user_addresses.count }.from(1).to(0)
|
104
|
+
|
105
|
+
expect(response.status).to eq(200)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'on behalf of address book owner' do
|
111
|
+
context 'with ability' do
|
112
|
+
before do
|
113
|
+
Spree::RoleConfiguration.configure do |config|
|
114
|
+
config.assign_permissions 'Prefect', [Spree::PermissionSets::UserManagement]
|
115
|
+
end
|
116
|
+
create(:user, spree_api_key: 'galleon', spree_roles: [build(:role, name: 'Prefect')])
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns another user's address book" do
|
120
|
+
other_user = create(:user)
|
121
|
+
other_user.save_in_address_book(harry_address_attributes, true)
|
122
|
+
other_user.save_in_address_book(ron_address_attributes, false)
|
123
|
+
|
124
|
+
get "/api/users/#{other_user.id}/address_book", nil, { 'X-SPREE-TOKEN' => 'galleon'}
|
125
|
+
|
126
|
+
json_response = JSON.parse(response.body)
|
127
|
+
expect(response.status).to eq(200)
|
128
|
+
expect(json_response.length).to eq(2)
|
129
|
+
expect(json_response).to include(
|
130
|
+
hash_including(harry_address_attributes.merge!('default' => true)),
|
131
|
+
hash_including(ron_address_attributes.merge!('default' => false)),
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "updates another user's address" do
|
136
|
+
other_user = create(:user)
|
137
|
+
address = other_user.save_in_address_book(harry_address_attributes, true)
|
138
|
+
updated_harry_address = harry_address_attributes.merge('firstname' => 'Ron')
|
139
|
+
|
140
|
+
expect {
|
141
|
+
put "/api/users/#{other_user.id}/address_book", { address_book: updated_harry_address.merge('id' => address.id) }, { 'X-SPREE-TOKEN' => 'galleon' }
|
142
|
+
}.to change { UserAddress.count }.from(1).to(2)
|
143
|
+
|
144
|
+
expect(response.status).to eq(200)
|
145
|
+
expect(JSON.parse(response.body).first).to include(updated_harry_address)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "archives another user's address" do
|
149
|
+
address = create(:address)
|
150
|
+
other_user = create(:user)
|
151
|
+
other_user.save_in_address_book(address.attributes, false)
|
152
|
+
|
153
|
+
expect {
|
154
|
+
delete "/api/users/#{other_user.id}/address_book", { address_id: address.id }, { 'X-SPREE-TOKEN' => 'galleon'}
|
155
|
+
}.to change { other_user.reload.user_addresses.count }.from(1).to(0)
|
156
|
+
|
157
|
+
expect(response.status).to eq(200)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'without ability' do
|
162
|
+
it 'does not return another user address book' do
|
163
|
+
create(:user, spree_api_key: 'galleon')
|
164
|
+
other_user = create(:user)
|
165
|
+
other_user.save_in_address_book(harry_address_attributes, true)
|
166
|
+
|
167
|
+
get "/api/users/#{other_user.id}/address_book", nil, { 'X-SPREE-TOKEN' => 'galleon'}
|
168
|
+
|
169
|
+
expect(response.status).to eq(401)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'does not update another user address' do
|
173
|
+
address = create(:address)
|
174
|
+
other_user = create(:user)
|
175
|
+
other_user_address = other_user.save_in_address_book(address.attributes, true)
|
176
|
+
create(:user, spree_api_key: 'galleon')
|
177
|
+
|
178
|
+
expect {
|
179
|
+
put "/api/users/#{other_user.id}/address_book", { address_book: other_user_address.attributes.merge('address1' => 'Hogwarts') }, { 'X-SPREE-TOKEN' => 'galleon' }
|
180
|
+
}.not_to change { UserAddress.count }
|
181
|
+
|
182
|
+
expect(response.status).to eq(401)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'does not archive another user address' do
|
186
|
+
address = create(:address)
|
187
|
+
other_user = create(:user)
|
188
|
+
other_user.save_in_address_book(address.attributes, true)
|
189
|
+
create(:user, spree_api_key: 'galleon')
|
190
|
+
|
191
|
+
expect {
|
192
|
+
delete "/api/users/#{other_user.id}/address_book", { address_id: address.id }, { 'X-SPREE-TOKEN' => 'galleon' }
|
193
|
+
}.not_to change { other_user.user_addresses.count }
|
194
|
+
|
195
|
+
expect(response.status).to eq(401)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
context 'unauthenticated' do
|
202
|
+
before do
|
203
|
+
@user = create(:user)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'GET returns a 401' do
|
207
|
+
get "/api/users/#{@user.id}/address_book"
|
208
|
+
expect(response.status).to eq(401)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'UPDATE returns a 401' do
|
212
|
+
put "/api/users/#{@user.id}/address_book"
|
213
|
+
expect(response.status).to eq(401)
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'DELETE returns a 401' do
|
217
|
+
delete "/api/users/#{@user.id}/address_book"
|
218
|
+
expect(response.status).to eq(401)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.
|
4
|
+
version: 1.1.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.1.0.
|
19
|
+
version: 1.1.0.pre2
|
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: 1.1.0.
|
26
|
+
version: 1.1.0.pre2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -215,7 +215,6 @@ files:
|
|
215
215
|
- lib/spree_api.rb
|
216
216
|
- script/rails
|
217
217
|
- solidus_api.gemspec
|
218
|
-
- spec/controllers/spree/api/address_books_controller_spec.rb
|
219
218
|
- spec/controllers/spree/api/addresses_controller_spec.rb
|
220
219
|
- spec/controllers/spree/api/base_controller_spec.rb
|
221
220
|
- spec/controllers/spree/api/checkouts_controller_spec.rb
|
@@ -255,6 +254,7 @@ files:
|
|
255
254
|
- spec/features/checkout_spec.rb
|
256
255
|
- spec/fixtures/thinking-cat.jpg
|
257
256
|
- spec/models/spree/legacy_user_spec.rb
|
257
|
+
- spec/requests/api/address_books_spec.rb
|
258
258
|
- spec/requests/rabl_cache_spec.rb
|
259
259
|
- spec/requests/ransackable_attributes_spec.rb
|
260
260
|
- spec/shared_examples/protect_product_actions.rb
|
@@ -289,7 +289,6 @@ signing_key:
|
|
289
289
|
specification_version: 4
|
290
290
|
summary: REST API for the Solidus e-commerce framework.
|
291
291
|
test_files:
|
292
|
-
- spec/controllers/spree/api/address_books_controller_spec.rb
|
293
292
|
- spec/controllers/spree/api/addresses_controller_spec.rb
|
294
293
|
- spec/controllers/spree/api/base_controller_spec.rb
|
295
294
|
- spec/controllers/spree/api/checkouts_controller_spec.rb
|
@@ -329,6 +328,7 @@ test_files:
|
|
329
328
|
- spec/features/checkout_spec.rb
|
330
329
|
- spec/fixtures/thinking-cat.jpg
|
331
330
|
- spec/models/spree/legacy_user_spec.rb
|
331
|
+
- spec/requests/api/address_books_spec.rb
|
332
332
|
- spec/requests/rabl_cache_spec.rb
|
333
333
|
- spec/requests/ransackable_attributes_spec.rb
|
334
334
|
- spec/shared_examples/protect_product_actions.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
describe Api::AddressBooksController, :type => :controller do
|
5
|
-
render_views
|
6
|
-
|
7
|
-
context "unauthorized user" do
|
8
|
-
it "get 401 on /show" do
|
9
|
-
api_get :show
|
10
|
-
expect(response.status).to eq 401
|
11
|
-
end
|
12
|
-
|
13
|
-
it "get 401 on /update" do
|
14
|
-
api_put :update
|
15
|
-
expect(response.status).to eq 401
|
16
|
-
end
|
17
|
-
|
18
|
-
it "get 401 on /destroy" do
|
19
|
-
api_delete :destroy, address_id: 1
|
20
|
-
expect(response.status).to eq 401
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "authorized user with addresses" do
|
25
|
-
let(:address1) { create(:address) }
|
26
|
-
let(:address2) { create(:address, firstname: "Different") }
|
27
|
-
|
28
|
-
before do
|
29
|
-
stub_authentication!
|
30
|
-
current_api_user.save_in_address_book(address1.attributes, true)
|
31
|
-
current_api_user.save_in_address_book(address2.attributes, false)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "gets their address book" do
|
35
|
-
api_get :show
|
36
|
-
expect(json_response.length).to eq 2
|
37
|
-
end
|
38
|
-
|
39
|
-
it "the first one is default" do
|
40
|
-
api_get :show
|
41
|
-
first, second = *json_response
|
42
|
-
expect(first["default"]).to be true
|
43
|
-
expect(second["default"]).to be false
|
44
|
-
end
|
45
|
-
|
46
|
-
it "can remove an address" do
|
47
|
-
api_delete :destroy, address_id: address1.id
|
48
|
-
expect(json_response.length).to eq 1
|
49
|
-
end
|
50
|
-
|
51
|
-
it "can update an address" do
|
52
|
-
updated_params = address2.attributes
|
53
|
-
updated_params[:firstname] = "Johnny"
|
54
|
-
updated_params[:default] = true
|
55
|
-
api_put :update, address_book: updated_params
|
56
|
-
expect(json_response.first["firstname"]).to eq "Johnny"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|