Fix price duration

#475
This commit is contained in:
Artur Beljajev 2017-04-26 17:02:43 +03:00
parent a3b3490591
commit 22a2329ba5
7 changed files with 28 additions and 13 deletions

View file

@ -79,7 +79,8 @@ module Admin
end
def durations
::Billing::Price::durations
durations = ::Billing::Price::durations
durations.collect { |duration| [duration.sub('mon', 'month'), duration] }
end
end
end

View file

@ -17,9 +17,9 @@ module Billing
def self.durations
[
'3 months',
'6 months',
'9 months',
'3 mons',
'6 mons',
'9 mons',
'1 year',
'2 years',
'3 years',

View file

@ -1,10 +1,10 @@
<tr>
<td><%= price.zone_name %></td>
<td><%= price.duration %></td>
<td><%= price.duration.sub('mons', 'months') %></td>
<td><%= price.operation_category %></td>
<td><%= currency(price.price) %></td>
<td><%= l(price.valid_from, format: :ydate) %></td>
<td><%= l(price.valid_to, format: :ydate) %></td>
<td><%= l price.valid_from, format: :date %></td>
<td><%= l price.valid_to, format: :date %></td>
<td>
<%= link_to t('.edit_btn'), edit_admin_price_path(price), class: 'btn btn-xs btn-primary' %>
<%= link_to(t('.delete_btn'), admin_price_path(price),

View file

@ -27,7 +27,7 @@ RSpec.feature 'New price in admin area', settings: false do
def fill_form
select 'test', from: 'price_zone_id'
select Billing::Price.operation_categories.first, from: 'price_operation_category'
select Billing::Price.durations.first, from: 'price_duration'
select '3 months', from: 'price_duration'
fill_in 'price_price', with: '1'
end

View file

@ -13,9 +13,9 @@ RSpec.describe Billing::Price do
describe '::durations', db: false do
it 'returns available durations' do
durations = [
'3 months',
'6 months',
'9 months',
'3 mons',
'6 mons',
'9 mons',
'1 year',
'2 years',
'3 years',

View file

@ -24,7 +24,12 @@ RSpec.describe 'admin price create', settings: false do
expect(price.operation_category).to eq(Billing::Price.operation_categories.first)
end
it 'saves duration' do
it 'saves duration in months' do
post admin_prices_path, price: attributes_for(:price, zone_id: '1', duration: '3 mons')
expect(price.duration).to eq('3 mons')
end
it 'saves duration in years' do
post admin_prices_path, price: attributes_for(:price, zone_id: '1', duration: '1 year')
expect(price.duration).to eq('1 year')
end

View file

@ -25,7 +25,16 @@ RSpec.describe 'admin price update', settings: false do
expect(price.operation_category).to eq(Billing::Price.operation_categories.second)
end
it 'updates duration' do
it 'updates duration in months' do
price = create(:price, duration: '3 mons')
patch admin_price_path(price), price: attributes_for(:price, duration: '6 mons')
price.reload
expect(price.duration).to eq('6 mons')
end
it 'updates duration in years' do
price = create(:price, duration: '1 year')
patch admin_price_path(price), price: attributes_for(:price, duration: '2 years')