mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Update admin pages to allow entering an amount
This commit is contained in:
committed by
Maikel Linke
parent
15eee8175e
commit
b427e420ce
@@ -26,11 +26,11 @@ module Admin
|
||||
private
|
||||
|
||||
def load_enterprise
|
||||
@enterprise = Enterprise.find_by permalink: params[:enterprise_id]
|
||||
@enterprise = Enterprise.find_by(permalink: params[:enterprise_id])
|
||||
end
|
||||
|
||||
def permitted_resource_params
|
||||
params.require(:voucher).permit(:code)
|
||||
params.require(:voucher).permit(:code, :amount)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,4 +20,4 @@
|
||||
= f.label :amount, t('.voucher_amount')
|
||||
.omega.eight.columns
|
||||
= Spree::Money.currency_symbol
|
||||
= f.text_field :amount, value: @voucher.value, disabled: true
|
||||
= f.text_field :amount, value: @voucher.amount
|
||||
|
||||
52
spec/requests/admin/vouchers_controller_spec.rb
Normal file
52
spec/requests/admin/vouchers_controller_spec.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "spec_helper"
|
||||
|
||||
describe Admin::VouchersController, type: :request do
|
||||
let(:enterprise) { create(:supplier_enterprise, name: "Feedme") }
|
||||
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
|
||||
|
||||
before do
|
||||
Flipper.enable(:vouchers)
|
||||
|
||||
enterprise_user.enterprise_roles.build(enterprise: enterprise).save
|
||||
sign_in enterprise_user
|
||||
end
|
||||
|
||||
describe "GET /admin/enterprises/:enterprise_id/vouchers/new" do
|
||||
it "loads the new voucher page" do
|
||||
get new_admin_enterprise_voucher_path(enterprise)
|
||||
|
||||
expect(response).to render_template("admin/vouchers/new")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /admin/enterprises/:enterprise_id/vouchers" do
|
||||
subject(:create_voucher) { post admin_enterprise_vouchers_path(enterprise), params: params }
|
||||
|
||||
let(:params) do
|
||||
{
|
||||
voucher: {
|
||||
code: code,
|
||||
amount: amount
|
||||
}
|
||||
}
|
||||
end
|
||||
let(:code) { "new_code" }
|
||||
let(:amount) { 15 }
|
||||
|
||||
it "creates a new voucher" do
|
||||
expect { create_voucher }.to change(Voucher, :count).by(1)
|
||||
|
||||
voucher = Voucher.last
|
||||
expect(voucher.code).to eq(code)
|
||||
expect(voucher.amount).to eq(amount)
|
||||
end
|
||||
|
||||
it "redirects to admin enterprise setting page, voucher panel" do
|
||||
create_voucher
|
||||
|
||||
expect(response).to redirect_to("#{edit_admin_enterprise_path(enterprise)}#vouchers_panel")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,6 +11,7 @@ describe '
|
||||
|
||||
let(:enterprise) { create(:supplier_enterprise, name: 'Feedme') }
|
||||
let(:voucher_code) { 'awesomevoucher' }
|
||||
let(:amount) { 25 }
|
||||
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
|
||||
|
||||
before do
|
||||
@@ -22,7 +23,7 @@ describe '
|
||||
|
||||
it 'lists enterprise vouchers' do
|
||||
# Given an enterprise with vouchers
|
||||
Voucher.create!(enterprise: enterprise, code: voucher_code)
|
||||
Voucher.create!(enterprise: enterprise, code: voucher_code, amount: amount)
|
||||
|
||||
# When I go to the enterprise voucher tab
|
||||
visit edit_admin_enterprise_path(enterprise)
|
||||
@@ -31,7 +32,7 @@ describe '
|
||||
|
||||
# Then I see a list of vouchers
|
||||
expect(page).to have_content voucher_code
|
||||
expect(page).to have_content "10"
|
||||
expect(page).to have_content amount
|
||||
end
|
||||
|
||||
it 'creates a voucher' do
|
||||
@@ -46,12 +47,13 @@ describe '
|
||||
|
||||
# And I fill in the fields for a new voucher click save
|
||||
fill_in 'voucher_code', with: voucher_code
|
||||
fill_in 'voucher_amount', with: amount
|
||||
click_button 'Save'
|
||||
|
||||
# Then I should get redirect to the entreprise voucher tab and see the created voucher
|
||||
expect(page).to have_selector '.success', text: 'Voucher has been successfully created!'
|
||||
expect(page).to have_content voucher_code
|
||||
expect(page).to have_content "10"
|
||||
expect(page).to have_content amount
|
||||
|
||||
voucher = Voucher.where(enterprise: enterprise, code: voucher_code).first
|
||||
|
||||
|
||||
Reference in New Issue
Block a user