Skip to content
Browse files

Add a test for using display_with with a custom helper and a lambda

  • Loading branch information...
1 parent f7a7eb4 commit 966213713c903d977ee4950a8f53b646173d81b4 Roger Campos committed Oct 1, 2012
View
44 spec/integration/js_spec.rb
@@ -508,8 +508,18 @@
page.should have_content("$100.00")
end
end
-
-
+
+ it "should let me use custom helpers with a lambda" do
+ @user.save!
+ visit user_path(@user)
+
+ page.should have_content("100.0 €")
+ bip_text @user, :money_custom, "250"
+
+ within("#money_custom") do
+ page.should have_content("250.0 €")
+ end
+ end
it "should still show the custom format after an error" do
@user.save!
@@ -582,9 +592,9 @@
within("#alt_money") { page.should have_content("€58.00") }
end
-
+
describe "display_with using a lambda" do
-
+
it "should render the money" do
@user.save!
@@ -595,7 +605,7 @@
end
end
-
+
it "should show the new value using the helper after a successful update" do
@user.save!
@@ -644,9 +654,9 @@
text.should == "40"
end
end
-
+
end
-
+
end
it "should display strings with quotes correctly in fields" do
@@ -678,42 +688,42 @@
page.should have_link("link in this text", :href => "http://google.es")
end
end
-
+
it "should display single- and double-quotes in values appropriately" do
@user.height = %{5' 6"}
@user.save!
-
+
retry_on_timeout do
visit user_path(@user)
-
+
id = BestInPlace::Utils.build_best_in_place_id @user, :height
page.execute_script <<-JS
$("##{id}").click();
JS
-
+
page.find("##{id} select").value.should eq(%{5' 6"})
end
end
-
+
it "should save single- and double-quotes in values appropriately" do
@user.height = %{5' 10"}
@user.save!
-
+
retry_on_timeout do
visit user_path(@user)
-
+
id = BestInPlace::Utils.build_best_in_place_id @user, :height
page.execute_script <<-JS
$("##{id}").click();
$("##{id} select").val("5' 7\\\"");
$("##{id} select").blur();
JS
-
+
sleep 1
-
+
@user.reload
@user.height.should eq(%{5' 7"})
end
end
-
+
end
View
5 test_app/app/helpers/users_helper.rb
@@ -1,3 +1,4 @@
+#encoding: utf-8
module UsersHelper
def height_collection
[
@@ -21,4 +22,8 @@ def height_collection
%{6' 6"}
]
end
+
+ def bb(value)
+ "#{value}"
+ end
end
View
4 test_app/app/models/user.rb
@@ -14,7 +14,9 @@ class User < ActiveRecord::Base
validates :zip, :numericality => true, :length => { :minimum => 5 }
validates_numericality_of :money, :allow_blank => true
validates_numericality_of :money_proc, :allow_blank => true
-
+
+ alias_attribute :money_custom, :money
+
def address_format
"<b>addr => [#{address}]</b>".html_safe
end
View
6 test_app/app/views/users/show.html.erb
@@ -98,6 +98,12 @@
<%= best_in_place @user, :money_proc, :display_with => lambda{ |v| number_to_currency(v) } %>
</td>
</tr>
+ <tr>
+ <td>Money with custom helper</td>
+ <td id="money_custom">
+ <%= best_in_place @user, :money_custom, :display_with => lambda { |x| bb(x) } %>
+ </td>
+ </tr>
</table>
<br />
<hr />

0 comments on commit 9662137

Please sign in to comment.
Something went wrong with that request. Please try again.