Permalink
Browse files

Don't show the cheapest purchase if there is none

  • Loading branch information...
1 parent 62a13bb commit 8c9dfd866b60dc8ae6c08280534d0714a6078e29 @mike-burns mike-burns committed Oct 19, 2008
Showing with 26 additions and 13 deletions.
  1. +15 −13 app/views/purchases/_purchase.html.erb
  2. +11 −0 test/functional/purchases_controller_test.rb
View
28 app/views/purchases/_purchase.html.erb
@@ -6,19 +6,21 @@
<span class="location"><%=h purchase.store.name %></span>
</span>
<span class="your-price"><%= number_to_formatted_currency(purchase.price) %></span>
- <span class="cheapest-price closed">
- <%= link_to_remote number_to_formatted_currency(purchase.cheapest_price),
- :url => purchase_stores_path(purchase),
- :method => :get,
- :complete => "$('#{dom_id(purchase)}').down('.open').show(); " <<
- "$('#{dom_id(purchase)}').down('.closed').hide(); " %>
- </span>
- <span class="cheapest-price open" style="display: none">
- <%= link_to_function number_to_formatted_currency(purchase.cheapest_price),
- "new Effect.BlindUp('#{dom_id(purchase, :stores_for)}'); " <<
- "$('#{dom_id(purchase)}').down('.closed').show(); " <<
- "$('#{dom_id(purchase)}').down('.open').hide(); " %>
- </span>
+ <% unless purchase.cheapest_price.nil? %>
+ <span class="cheapest-price closed">
+ <%= link_to_remote number_to_formatted_currency(purchase.cheapest_price),
+ :url => purchase_stores_path(purchase),
+ :method => :get,
+ :complete => "$('#{dom_id(purchase)}').down('.open').show(); " <<
+ "$('#{dom_id(purchase)}').down('.closed').hide(); " %>
+ </span>
+ <span class="cheapest-price open" style="display: none">
+ <%= link_to_function number_to_formatted_currency(purchase.cheapest_price),
+ "new Effect.BlindUp('#{dom_id(purchase, :stores_for)}'); " <<
+ "$('#{dom_id(purchase)}').down('.closed').show(); " <<
+ "$('#{dom_id(purchase)}').down('.open').hide(); " %>
+ </span>
+ <% end %>
<%= link_to_remote '<span class="invisible">X</span>', {:url => purchase_path(purchase), :method => :delete }, :class => 'delete' %>
</div>
<% content_tag_for :div,
View
11 test/functional/purchases_controller_test.rb
@@ -96,6 +96,17 @@ def setup
assert_no_match @focus_quantity, @response.body
end
end
+
+ context "on GET to index without any nearby stores" do
+ setup do
+ @purchases.each {|purchase| purchase.stubs(:cheapest_price).returns(nil) }
+ get :index
+ end
+
+ should "not show the cheapest-price box" do
+ assert_select 'span.cheapest-price', false
+ end
+ end
end
context "on GET to index without any previous purchases" do

0 comments on commit 8c9dfd8

Please sign in to comment.