Skip to content

Commit

Permalink
Merge pull request #243 from lucymclaughlin/forex_link
Browse files Browse the repository at this point in the history
Forex link
  • Loading branch information
Skud committed Jul 4, 2013
2 parents 067fd27 + 778d7a6 commit e4dd0f9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -15,5 +15,14 @@ def parse_date(str)
return str == '' ? nil : Date.parse(str)
end

def forex_link(price)
pid = price_in_dollars(price)
currency = Growstuff::Application.config.currency
link = "http://www.wolframalpha.com/input/?i=#{pid}+#{currency}"
return link_to "(convert)",
link,
:target => "_blank"
end

end

7 changes: 6 additions & 1 deletion app/models/order.rb
Expand Up @@ -8,7 +8,12 @@ class Order < ActiveRecord::Base

# total price of an order
def total
order_items.to_a.sum(&:price)
sum = 0
for i in order_items do
subtotal = i.price * i.quantity
sum += subtotal
end
return sum
end

# return items in the format ActiveMerchant/PayPal want them
Expand Down
1 change: 1 addition & 0 deletions app/views/orders/show.html.haml
Expand Up @@ -51,6 +51,7 @@
%td
%strong
= price_with_currency(@order.total)
= forex_link(@order.total)

%p
- if can? :destroy, @order
Expand Down
2 changes: 2 additions & 0 deletions app/views/shop/index.html.haml
Expand Up @@ -55,10 +55,12 @@
Pay what you want, starting at
=succeed "." do
=price_with_currency(p.min_price)
=forex_link(p.min_price)
- if p.recommended_price
Recommended price:
=succeed "." do
=price_with_currency(p.recommended_price)
=forex_link(p.recommended_price)

%div
- if can? :create, Order
Expand Down
18 changes: 16 additions & 2 deletions spec/models/order_spec.rb
Expand Up @@ -45,9 +45,23 @@
# we force an order to only have one item at present. Add more if wanted
# later.
@order_item1 = FactoryGirl.create(:order_item,
:order_id => @order.id, :product_id => @product.id, :price => 1111)
:order_id => @order.id, :product_id => @product.id, :price => 1111, :quantity => 1)

@order.total.should eq 1111
end

it "gives the correct total for quantities more than 1" do
@member = FactoryGirl.create(:member)
@order = FactoryGirl.create(:order, :member => @member)
@product = FactoryGirl.create(:product,
:min_price => 1000
)
# we force an order to only have one item at present. Add more if wanted
# later.
@order_item1 = FactoryGirl.create(:order_item,
:order_id => @order.id, :product_id => @product.id, :price => 1111, :quantity => 2)

@order.total.should eq 1111
@order.total.should eq 2222
end

it "formats order items for activemerchant" do
Expand Down
7 changes: 6 additions & 1 deletion spec/views/orders/show.html.haml_spec.rb
Expand Up @@ -29,7 +29,12 @@

it "shows the total" do
rendered.should contain "Total:"
rendered.should contain "198.00"
assert_select "strong", /198.00/
end

it "shows a foreign exchange link for the total" do
currency = Growstuff::Application.config.currency
assert_select("a[href=http://www.wolframalpha.com/input/?i=198.00+#{currency}]")
end

it "shows a checkout button" do
Expand Down
10 changes: 10 additions & 0 deletions spec/views/shop/index_spec.rb
Expand Up @@ -23,10 +23,20 @@
rendered.should contain '9.99 AUD'
end

it 'should contain an exchange rate link' do
currency = Growstuff::Application.config.currency
assert_select("a[href=http://www.wolframalpha.com/input/?i=9.99+#{currency}]")
end

it 'shows recommended price for products that have it' do
rendered.should contain '12.00 AUD'
end

it 'should contain an exchange rate link for recommended price' do
currency = Growstuff::Application.config.currency
assert_select("a[href=http://www.wolframalpha.com/input/?i=12.00+#{currency}]")
end

it 'displays the order form' do
assert_select "form", :count => 2
end
Expand Down

0 comments on commit e4dd0f9

Please sign in to comment.