Skip to content

Commit 764d065

Browse files
committed
PC-50: Fixed Item admin specs
1 parent ba7cb6b commit 764d065

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

app/admin/items.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def apply_tmp_params(item, tmp)
268268

269269
if param_name.blank?
270270
flash[:error] = "Parameter name can't be blank"
271-
return redirect_back(fallback_location: edit_admin_item_path(@item))
271+
return redirect_back(fallback_location: @item&.id ? edit_admin_item_path(@item) : new_admin_item_path)
272272
end
273273

274274
store[:formula_parameters] << param_name unless store[:formula_parameters].include?(param_name)
@@ -284,7 +284,6 @@ def apply_tmp_params(item, tmp)
284284
when "Select"
285285
sub_hash = {}
286286

287-
# Отримаємо масив select_options з параметрів
288287
select_options = params[:select_options] || []
289288

290289
select_options.each do |pair|
@@ -298,7 +297,7 @@ def apply_tmp_params(item, tmp)
298297
value_label = params[:value_label]
299298
if value_label.blank?
300299
flash[:error] = "Value Label is required for Select parameter"
301-
return redirect_back(fallback_location: edit_admin_item_path(@item))
300+
return redirect_back(fallback_location: @item&.id ? edit_admin_item_path(@item) : new_admin_item_path)
302301
end
303302

304303
store[:select][param_name] = {
@@ -308,7 +307,7 @@ def apply_tmp_params(item, tmp)
308307

309308
else
310309
flash[:error] = "Unknown parameter type"
311-
return redirect_back(fallback_location: edit_admin_item_path(@item))
310+
return redirect_back(fallback_location: @item&.id ? edit_admin_item_path(@item) : new_admin_item_path)
312311
end
313312

314313
session[:tmp_params][item_key] = store.deep_stringify_keys

spec/requests/admin/items_controller_spec.rb

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
category: category,
3030
fixed_parameters: { 'Platform Fee' => '1000' },
3131
open_parameters_label: ['Users'],
32-
pricing_options: { 'Tier' => { 'Silver' => '150' } },
32+
pricing_options: { "Tier" => { "options" => { "Silver" => "200" }, "value_label" => "Cost Per User" } },
3333
calculation_formula: 'Platform Fee * Tier')
3434
end
3535

@@ -43,7 +43,8 @@
4343
expect(response.body).to include('Users')
4444
expect(response.body).to include('Tier')
4545
expect(response.body).to include('Silver')
46-
expect(response.body).to include('150')
46+
expect(response.body).to include('200')
47+
expect(response.body).to include('Cost Per User')
4748
expect(response.body).to include('Platform Fee * Tier')
4849
end
4950
end
@@ -88,8 +89,10 @@
8889
post '/admin/items/new/create_parameter', params: {
8990
parameter_type: 'Select',
9091
select_parameter_name: 'Tier',
91-
option_description_1: '1-5', # rubocop:disable Naming/VariableNumber
92-
option_value_1: '100' # rubocop:disable Naming/VariableNumber
92+
value_label: 'Cost Per User',
93+
select_options: [
94+
{ description: '1-5', value: '100' }
95+
]
9396
}
9497

9598
post '/admin/items/new/update_formula', params: {
@@ -105,7 +108,7 @@
105108
item = Item.last
106109
expect(item.fixed_parameters).to eq('Acquisition' => '2500')
107110
expect(item.open_parameters_label).to eq(['Custom'])
108-
expect(item.pricing_options).to eq('Tier' => { '1-5' => '100' })
111+
expect(item.pricing_options).to eq("Tier" => { "options" => { "1-5" => "100" }, "value_label" => "Cost Per User" })
109112
expect(item.formula_parameters).to eq(%w[Acquisition Custom Tier])
110113
expect(item.calculation_formula).to eq('Acquisition * Tier')
111114
expect(item.is_fixed).to be true
@@ -199,8 +202,10 @@
199202
post '/admin/items/new/create_parameter', params: {
200203
parameter_type: 'Select',
201204
select_parameter_name: 'Tier',
202-
option_description_1: '1-5', # rubocop:disable Naming/VariableNumber
203-
option_value_1: '100' # rubocop:disable Naming/VariableNumber
205+
value_label: 'Cost Per User',
206+
select_options: [
207+
{ description: '1-5', value: '100' }
208+
]
204209
}
205210

206211
post '/admin/items/new/update_formula', params: {
@@ -228,16 +233,4 @@
228233
expect(response.body).not_to include('Tier')
229234
end
230235
end
231-
232-
describe 'POST /admin/items/:id/update_formula' do
233-
it 'updates the calculation formula for a persisted item' do
234-
post "/admin/items/#{item.id}/update_formula", params: {
235-
calculation_formula: 'NewFormula * 2'
236-
}
237-
item.reload
238-
expect(item.calculation_formula).to eq('NewFormula * 2')
239-
expect(response).to redirect_to("/admin/items/#{item.id}/edit")
240-
expect(flash[:notice]).to eq('Formula saved!')
241-
end
242-
end
243236
end

0 commit comments

Comments
 (0)