-
-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10761 from rioug/vouchers-any-amount
[Vouchers] Flat rate of any amount
- Loading branch information
Showing
17 changed files
with
111 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAmountToVouchers < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :vouchers, :amount, :decimal, precision: 10, scale: 2, null: false, default: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :voucher do | ||
enterprise { build(:distributor_enterprise) } | ||
amount { 15 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters