-
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.
- Loading branch information
Artur Beljajev
committed
May 25, 2017
1 parent
3741e2d
commit 58ae53b
Showing
17 changed files
with
264 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Concerns::Billing::Price::Expirable | ||
extend ActiveSupport::Concern | ||
|
||
class_methods do | ||
def unexpired | ||
where("#{attribute_alias(:expire_time)} >= ?", Time.zone.now) | ||
end | ||
|
||
def expired | ||
where("#{attribute_alias(:expire_time)} < ?", Time.zone.now) | ||
end | ||
end | ||
|
||
def expire | ||
self[:valid_to] = Time.zone.now - 1 | ||
end | ||
|
||
def expired? | ||
expire_time.past? | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= form_for :search, url: admin_prices_path, method: :get, html: { class: 'form-horizontal' } do |f| %> | ||
<div class="form-group"> | ||
<%= f.label :validity, class: 'col-sm-2 control-label' %> | ||
|
||
<div class="col-sm-3"> | ||
<%= f.select :validity, options_for_select(%w[unexpired expired], search.validity), | ||
{ include_blank: true }, | ||
class: 'form-control' %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-offset-2 col-sm-8"> | ||
<%= f.submit t('.search_btn'), class: 'btn btn-primary', name: nil %> | ||
<%= link_to t('.reset_btn'), admin_prices_path, | ||
class: 'btn btn-default price-search-form-search-btn' %> | ||
</div> | ||
</div> | ||
|
||
<% 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
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 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Expiring price in admin area', settings: false do | ||
given!(:price) { create(:unexpired_price) } | ||
|
||
background do | ||
sign_in_to_admin_area | ||
end | ||
|
||
scenario 'expires price' do | ||
visit admin_prices_path | ||
open_edit_form | ||
expire | ||
|
||
expect(page).to have_text(t('admin.billing.prices.expire.expired')) | ||
end | ||
|
||
def open_edit_form | ||
find('.edit-price-btn').click | ||
end | ||
|
||
def expire | ||
click_link_or_button t('admin.billing.prices.edit.expire_btn') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.feature 'Viewing prices in admin area', settings: false do | ||
given!(:unexpired_price) { create(:unexpired_price) } | ||
given!(:expired_price) { create(:expired_price) } | ||
|
||
background do | ||
sign_in_to_admin_area | ||
end | ||
|
||
describe 'search' do | ||
context 'when validity is not selected' do | ||
scenario 'shows unexpired prices' do | ||
visit admin_prices_path | ||
expect(page).to have_css('.price', count: 1) | ||
end | ||
end | ||
|
||
context 'when validity is given' do | ||
scenario 'filters by given validity' do | ||
visit admin_prices_path | ||
select 'unexpired', from: 'search_validity' | ||
submit_search_form | ||
|
||
expect(page).to have_css('.price', count: 1) | ||
end | ||
end | ||
|
||
def submit_search_form | ||
find('.price-search-form-search-btn').click | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Billing::Price do | ||
describe '::unexpired' do | ||
before :example do | ||
travel_to Time.zone.parse('05.07.2010 00:00') | ||
|
||
create(:price, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59')) | ||
create(:price, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00')) | ||
create(:price, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01')) | ||
end | ||
|
||
it 'returns prices with expire time in the future ' do | ||
expect(described_class.unexpired.ids).to eq([2, 3]) | ||
end | ||
end | ||
|
||
describe '::expired' do | ||
before :example do | ||
travel_to Time.zone.parse('05.07.2010 00:00') | ||
|
||
create(:price, id: 1, expire_time: Time.zone.parse('04.07.2010 23:59')) | ||
create(:price, id: 2, expire_time: Time.zone.parse('05.07.2010 00:00')) | ||
create(:price, id: 3, expire_time: Time.zone.parse('05.07.2010 00:01')) | ||
end | ||
|
||
it 'returns prices with expire time in the past ' do | ||
expect(described_class.expired.ids).to eq([1]) | ||
end | ||
end | ||
|
||
describe '#expire', db: false do | ||
let(:price) { described_class.new(expire_time: Time.zone.parse('06.07.2010')) } | ||
|
||
before :example do | ||
travel_to Time.zone.parse('05.07.2010 00:00') | ||
end | ||
|
||
it 'expires price' do | ||
expect { price.expire }.to change { price.expired? }.from(false).to(true) | ||
end | ||
end | ||
|
||
describe '#expired?', db: false do | ||
subject(:expired) { domain.expired? } | ||
|
||
before :example do | ||
travel_to Time.zone.parse('05.07.2010 00:00') | ||
end | ||
|
||
context 'when expire time is in the past' do | ||
let(:domain) { described_class.new(expire_time: Time.zone.parse('04.07.2010 23:59')) } | ||
|
||
specify { expect(expired).to be true } | ||
end | ||
|
||
context 'when expire time is now' do | ||
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:00')) } | ||
|
||
specify { expect(expired).to be false } | ||
end | ||
|
||
context 'when expire time is in the future' do | ||
let(:domain) { described_class.new(expire_time: Time.zone.parse('05.07.2010 00:01')) } | ||
|
||
specify { expect(expired).to be false } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'admin price expire', settings: false do | ||
before :example do | ||
sign_in_to_admin_area | ||
end | ||
|
||
it 'expires price' do | ||
price = create(:unexpired_price) | ||
|
||
expect { patch expire_admin_price_path(price); price.reload } | ||
.to change { price.expired? }.from(false).to(true) | ||
end | ||
|
||
it 'redirects to :index' do | ||
price = create(:unexpired_price) | ||
|
||
patch expire_admin_price_path(price) | ||
|
||
expect(response).to redirect_to admin_prices_url | ||
end | ||
end |