-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide expire button in price edit form if price is expired
- Loading branch information
Artur Beljajev
committed
Aug 29, 2017
1 parent
d807703
commit af6f745
Showing
5 changed files
with
59 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Billing | ||
class PricePresenter | ||
def initialize(price:, view:) | ||
@price = price | ||
@view = view | ||
end | ||
|
||
def expire_btn | ||
return if price.expired? | ||
|
||
view.link_to(view.t('admin.billing.prices.expire_btn.label'), | ||
view.expire_admin_price_path(price), | ||
method: :patch, | ||
data: { | ||
confirm: view.t('admin.billing.prices.expire_btn.confirm'), | ||
}, | ||
class: 'btn btn-danger') | ||
end | ||
|
||
private | ||
|
||
attr_reader :price | ||
attr_reader :view | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Billing::PricePresenter do | ||
let(:presenter) { described_class.new(price: price, view: view) } | ||
|
||
describe '#expire_btn' do | ||
context 'when price is not expired' do | ||
let(:price) { instance_double(Billing::Price, expired?: false) } | ||
|
||
it 'returns expire button' do | ||
html = view.link_to(t('admin.billing.prices.expire_btn.label'), expire_admin_price_path(price), | ||
method: :patch, | ||
data: { | ||
confirm: view.t('admin.billing.prices.expire_btn.confirm'), | ||
}, | ||
class: 'btn btn-danger') | ||
expect(presenter.expire_btn).to eq(html) | ||
end | ||
end | ||
|
||
context 'when price is expired' do | ||
let(:price) { instance_double(Billing::Price, expired?: true) } | ||
specify { expect(presenter.expire_btn).to be_nil } | ||
end | ||
end | ||
end |