very_best_in_place 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +14 -0
  5. data/CHANGELOG.md +36 -0
  6. data/Gemfile +8 -0
  7. data/README.md +438 -0
  8. data/Rakefile +8 -0
  9. data/best_in_place.gemspec +26 -0
  10. data/lib/assets/javascripts/best_in_place.js +722 -0
  11. data/lib/assets/javascripts/best_in_place.purr.js +10 -0
  12. data/lib/assets/javascripts/jquery.purr.js +161 -0
  13. data/lib/best_in_place.rb +12 -0
  14. data/lib/best_in_place/check_version.rb +8 -0
  15. data/lib/best_in_place/controller_extensions.rb +28 -0
  16. data/lib/best_in_place/display_methods.rb +44 -0
  17. data/lib/best_in_place/engine.rb +8 -0
  18. data/lib/best_in_place/helper.rb +128 -0
  19. data/lib/best_in_place/railtie.rb +7 -0
  20. data/lib/best_in_place/test_helpers.rb +41 -0
  21. data/lib/best_in_place/utils.rb +21 -0
  22. data/lib/best_in_place/version.rb +3 -0
  23. data/spec/helpers/best_in_place_spec.rb +407 -0
  24. data/spec/integration/double_init_spec.rb +34 -0
  25. data/spec/integration/js_spec.rb +959 -0
  26. data/spec/integration/live_spec.rb +40 -0
  27. data/spec/integration/text_area_spec.rb +40 -0
  28. data/spec/spec_helper.rb +23 -0
  29. data/spec/support/retry_on_timeout.rb +10 -0
  30. data/test_app/Gemfile +16 -0
  31. data/test_app/README +256 -0
  32. data/test_app/Rakefile +7 -0
  33. data/test_app/app/assets/images/no.png +0 -0
  34. data/test_app/app/assets/images/red_pen.png +0 -0
  35. data/test_app/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  36. data/test_app/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  37. data/test_app/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
  38. data/test_app/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  39. data/test_app/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  40. data/test_app/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  41. data/test_app/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  42. data/test_app/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  43. data/test_app/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  44. data/test_app/app/assets/images/ui-icons_222222_256x240.png +0 -0
  45. data/test_app/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
  46. data/test_app/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
  47. data/test_app/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
  48. data/test_app/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
  49. data/test_app/app/assets/images/yes.png +0 -0
  50. data/test_app/app/assets/javascripts/application.js +35 -0
  51. data/test_app/app/assets/stylesheets/.gitkeep +0 -0
  52. data/test_app/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +357 -0
  53. data/test_app/app/assets/stylesheets/scaffold.css +60 -0
  54. data/test_app/app/assets/stylesheets/style.css.erb +79 -0
  55. data/test_app/app/controllers/admin/users_controller.rb +14 -0
  56. data/test_app/app/controllers/application_controller.rb +3 -0
  57. data/test_app/app/controllers/cuca/cars_controller.rb +16 -0
  58. data/test_app/app/controllers/users_controller.rb +99 -0
  59. data/test_app/app/helpers/application_helper.rb +2 -0
  60. data/test_app/app/helpers/users_helper.rb +29 -0
  61. data/test_app/app/models/cuca/car.rb +5 -0
  62. data/test_app/app/models/user.rb +27 -0
  63. data/test_app/app/views/admin/users/show.html.erb +20 -0
  64. data/test_app/app/views/cuca/cars/show.html.erb +13 -0
  65. data/test_app/app/views/layouts/application.html.erb +14 -0
  66. data/test_app/app/views/users/_form.html.erb +51 -0
  67. data/test_app/app/views/users/double_init.html.erb +72 -0
  68. data/test_app/app/views/users/email_field.html.erb +1 -0
  69. data/test_app/app/views/users/index.html.erb +25 -0
  70. data/test_app/app/views/users/new.html.erb +5 -0
  71. data/test_app/app/views/users/show.html.erb +135 -0
  72. data/test_app/app/views/users/show_ajax.html.erb +12 -0
  73. data/test_app/config.ru +4 -0
  74. data/test_app/config/application.rb +51 -0
  75. data/test_app/config/boot.rb +13 -0
  76. data/test_app/config/database.yml +22 -0
  77. data/test_app/config/environment.rb +5 -0
  78. data/test_app/config/environments/development.rb +25 -0
  79. data/test_app/config/environments/production.rb +49 -0
  80. data/test_app/config/environments/test.rb +35 -0
  81. data/test_app/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test_app/config/initializers/countries.rb +1 -0
  83. data/test_app/config/initializers/default_date_format.rb +2 -0
  84. data/test_app/config/initializers/inflections.rb +10 -0
  85. data/test_app/config/initializers/mime_types.rb +5 -0
  86. data/test_app/config/initializers/secret_token.rb +7 -0
  87. data/test_app/config/initializers/session_store.rb +8 -0
  88. data/test_app/config/locales/en.yml +5 -0
  89. data/test_app/config/routes.rb +20 -0
  90. data/test_app/db/migrate/20101206205922_create_users.rb +18 -0
  91. data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +9 -0
  92. data/test_app/db/migrate/20110115204441_add_description_to_user.rb +9 -0
  93. data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +5 -0
  94. data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +5 -0
  95. data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +5 -0
  96. data/test_app/db/migrate/20111224181356_add_money_to_user.rb +5 -0
  97. data/test_app/db/migrate/20120513003308_create_cars.rb +11 -0
  98. data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +5 -0
  99. data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +6 -0
  100. data/test_app/db/migrate/20120620165212_add_height_to_user.rb +5 -0
  101. data/test_app/db/schema.rb +40 -0
  102. data/test_app/db/seeds.rb +19 -0
  103. data/test_app/doc/README_FOR_APP +2 -0
  104. data/test_app/lib/tasks/.gitkeep +0 -0
  105. data/test_app/lib/tasks/cron.rake +7 -0
  106. data/test_app/public/404.html +26 -0
  107. data/test_app/public/422.html +26 -0
  108. data/test_app/public/500.html +26 -0
  109. data/test_app/public/favicon.ico +0 -0
  110. data/test_app/public/robots.txt +5 -0
  111. data/test_app/script/rails +6 -0
  112. data/test_app/test/fixtures/users.yml +17 -0
  113. data/test_app/test/functional/users_controller_test.rb +49 -0
  114. data/test_app/test/performance/browsing_test.rb +9 -0
  115. data/test_app/test/test_helper.rb +13 -0
  116. data/test_app/test/unit/helpers/users_helper_test.rb +4 -0
  117. data/test_app/test/unit/user_test.rb +8 -0
  118. data/test_app/vendor/plugins/.gitkeep +0 -0
  119. metadata +241 -0
@@ -0,0 +1,21 @@
1
+ module BestInPlace
2
+ module Utils
3
+ extend self
4
+
5
+ def build_best_in_place_id(object, field)
6
+ if object.is_a?(Symbol) || object.is_a?(String)
7
+ return "best_in_place_#{object}_#{field}"
8
+ end
9
+
10
+ id = "best_in_place_#{object_to_key(object)}"
11
+ id << "_#{object.id}" if object.class.ancestors.include?(ActiveModel::Serializers::JSON)
12
+ id << "_#{field}"
13
+ id
14
+ end
15
+
16
+ def object_to_key(object)
17
+ return object.class.to_s.underscore unless object.class.respond_to?(:model_name)
18
+ ActiveModel::Naming.param_key(object.class)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module BestInPlace
2
+ VERSION = "2.0.3"
3
+ end
@@ -0,0 +1,407 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe BestInPlace::BestInPlaceHelpers do
5
+ describe "#best_in_place" do
6
+ before do
7
+ @user = User.new :name => "Lucia",
8
+ :last_name => "Napoli",
9
+ :email => "lucianapoli@gmail.com",
10
+ :height => "5' 5\"",
11
+ :address => "Via Roma 99",
12
+ :zip => "25123",
13
+ :country => "2",
14
+ :receive_email => false,
15
+ :birth_date => Time.now.utc.to_date,
16
+ :description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
17
+ :money => 150
18
+ end
19
+
20
+ it "should generate a proper id for namespaced models" do
21
+ @car = Cuca::Car.create :model => "Ford"
22
+
23
+ nk = Nokogiri::HTML.parse(helper.best_in_place @car, :model, :path => helper.cuca_cars_path)
24
+ span = nk.css("span")
25
+ span.attribute("id").value.should == "best_in_place_cuca_car_#{@car.id}_model"
26
+ end
27
+
28
+ it "should generate a proper span" do
29
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
30
+ span = nk.css("span")
31
+ span.should_not be_empty
32
+ end
33
+
34
+ it "should not allow both display_as and display_with option" do
35
+ lambda { helper.best_in_place(@user, :money, :display_with => :number_to_currency, :display_as => :custom) }.should raise_error(ArgumentError)
36
+ end
37
+
38
+ describe "general properties" do
39
+ before do
40
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
41
+ @span = nk.css("span")
42
+ end
43
+
44
+ context "when it's an ActiveRecord model" do
45
+ it "should have a proper id" do
46
+ @span.attribute("id").value.should == "best_in_place_user_#{@user.id}_name"
47
+ end
48
+ end
49
+
50
+ context "when it's not an AR model" do
51
+ it "shold generate an html id without any id" do
52
+ nk = Nokogiri::HTML.parse(helper.best_in_place [1,2,3], :first, :path => @user)
53
+ span = nk.css("span")
54
+ span.attribute("id").value.should == "best_in_place_array_first"
55
+ end
56
+ end
57
+
58
+ it "should have the best_in_place class" do
59
+ @span.attribute("class").value.should == "best_in_place"
60
+ end
61
+
62
+ it "should have the correct data-attribute" do
63
+ @span.attribute("data-attribute").value.should == "name"
64
+ end
65
+
66
+ it "should have the correct data-object" do
67
+ @span.attribute("data-object").value.should == "user"
68
+ end
69
+
70
+ it "should have no activator by default" do
71
+ @span.attribute("data-activator").should be_nil
72
+ end
73
+
74
+ it "should have no OK button text by default" do
75
+ @span.attribute("data-ok-button").should be_nil
76
+ end
77
+
78
+ it "should have no Cancel button text by default" do
79
+ @span.attribute("data-cancel-button").should be_nil
80
+ end
81
+
82
+ it "should have no Use-Confirmation dialog option by default" do
83
+ @span.attribute("data-use-confirm").should be_nil
84
+ end
85
+
86
+ it "should have no inner_class by default" do
87
+ @span.attribute("data-inner-class").should be_nil
88
+ end
89
+
90
+ describe "url generation" do
91
+ it "should have the correct default url" do
92
+ @user.save!
93
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
94
+ span = nk.css("span")
95
+ span.attribute("data-url").value.should == "/users/#{@user.id}"
96
+ end
97
+
98
+ it "should use the custom url specified in string format" do
99
+ out = helper.best_in_place @user, :name, :path => "/custom/path"
100
+ nk = Nokogiri::HTML.parse(out)
101
+ span = nk.css("span")
102
+ span.attribute("data-url").value.should == "/custom/path"
103
+ end
104
+
105
+ it "should use the path given in a named_path format" do
106
+ out = helper.best_in_place @user, :name, :path => helper.users_path
107
+ nk = Nokogiri::HTML.parse(out)
108
+ span = nk.css("span")
109
+ span.attribute("data-url").value.should == "/users"
110
+ end
111
+
112
+ it "should use the given path in a hash format" do
113
+ out = helper.best_in_place @user, :name, :path => {:controller => :users, :action => :edit, :id => 23}
114
+ nk = Nokogiri::HTML.parse(out)
115
+ span = nk.css("span")
116
+ span.attribute("data-url").value.should == "/users/23/edit"
117
+ end
118
+ end
119
+
120
+ describe "nil option" do
121
+ it "should have no nil data by default" do
122
+ @span.attribute("data-nil").should be_nil
123
+ end
124
+
125
+ it "should show '' if the object responds with nil for the passed attribute" do
126
+ @user.stub!(:name).and_return(nil)
127
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
128
+ span = nk.css("span")
129
+ span.text.should == ""
130
+ end
131
+
132
+ it "should show '' if the object responds with an empty string for the passed attribute" do
133
+ @user.stub!(:name).and_return("")
134
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
135
+ span = nk.css("span")
136
+ span.text.should == ""
137
+ end
138
+ end
139
+
140
+ it "should have the given inner_class" do
141
+ out = helper.best_in_place @user, :name, :inner_class => "awesome"
142
+ nk = Nokogiri::HTML.parse(out)
143
+ span = nk.css("span")
144
+ span.attribute("data-inner-class").value.should == "awesome"
145
+ end
146
+
147
+ it "should have the given activator" do
148
+ out = helper.best_in_place @user, :name, :activator => "awesome"
149
+ nk = Nokogiri::HTML.parse(out)
150
+ span = nk.css("span")
151
+ span.attribute("data-activator").value.should == "awesome"
152
+ end
153
+
154
+ it "should have the given OK button text" do
155
+ out = helper.best_in_place @user, :name, :ok_button => "okay"
156
+ nk = Nokogiri::HTML.parse(out)
157
+ span = nk.css("span")
158
+ span.attribute("data-ok-button").value.should == "okay"
159
+ end
160
+
161
+ it "should have the given Cancel button text" do
162
+ out = helper.best_in_place @user, :name, :cancel_button => "nasty"
163
+ nk = Nokogiri::HTML.parse(out)
164
+ span = nk.css("span")
165
+ span.attribute("data-cancel-button").value.should == "nasty"
166
+ end
167
+
168
+ it "should have the given Use-Confirmation dialog option" do
169
+ out = helper.best_in_place @user, :name, :use_confirm => "false"
170
+ nk = Nokogiri::HTML.parse(out)
171
+ span = nk.css("span")
172
+ span.attribute("data-use-confirm").value.should == "false"
173
+ end
174
+
175
+ describe "object_name" do
176
+ it "should change the data-object value" do
177
+ out = helper.best_in_place @user, :name, :object_name => "my_user"
178
+ nk = Nokogiri::HTML.parse(out)
179
+ span = nk.css("span")
180
+ span.attribute("data-object").value.should == "my_user"
181
+ end
182
+ end
183
+
184
+ it "should have html5 data attributes" do
185
+ out = helper.best_in_place @user, :name, :data => { :foo => "awesome", :bar => "nasty" }
186
+ nk = Nokogiri::HTML.parse(out)
187
+ span = nk.css("span")
188
+ span.attribute("data-foo").value.should == "awesome"
189
+ span.attribute("data-bar").value.should == "nasty"
190
+ end
191
+
192
+ describe "display_as" do
193
+ it "should render the address with a custom renderer" do
194
+ @user.should_receive(:address_format).and_return("the result")
195
+ out = helper.best_in_place @user, :address, :display_as => :address_format
196
+ nk = Nokogiri::HTML.parse(out)
197
+ span = nk.css("span")
198
+ span.text.should == "the result"
199
+ end
200
+ end
201
+
202
+ describe "display_with" do
203
+ it "should render the money with the given view helper" do
204
+ out = helper.best_in_place @user, :money, :display_with => :number_to_currency
205
+ nk = Nokogiri::HTML.parse(out)
206
+ span = nk.css("span")
207
+ span.text.should == "$150.00"
208
+ end
209
+
210
+ it "accepts a proc" do
211
+ out = helper.best_in_place @user, :name, :display_with => Proc.new { |v| v.upcase }
212
+ nk = Nokogiri::HTML.parse(out)
213
+ span = nk.css("span")
214
+ span.text.should == "LUCIA"
215
+ end
216
+
217
+ it "should raise an error if the given helper can't be found" do
218
+ lambda { helper.best_in_place @user, :money, :display_with => :fk_number_to_currency }.should raise_error(ArgumentError)
219
+ end
220
+
221
+ it "should call the helper method with the given arguments" do
222
+ out = helper.best_in_place @user, :money, :display_with => :number_to_currency, :helper_options => {:unit => "º"}
223
+ nk = Nokogiri::HTML.parse(out)
224
+ span = nk.css("span")
225
+ span.text.should == "º150.00"
226
+ end
227
+ end
228
+
229
+ describe "array-like objects" do
230
+ it "should work with array-like objects in order to provide support to namespaces" do
231
+ nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @user], :name)
232
+ span = nk.css("span")
233
+ span.text.should == "Lucia"
234
+ end
235
+ end
236
+ end
237
+
238
+ context "with a text field attribute" do
239
+ before do
240
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
241
+ @span = nk.css("span")
242
+ end
243
+
244
+ it "should render the name as text" do
245
+ @span.text.should == "Lucia"
246
+ end
247
+
248
+ it "should have an input data-type" do
249
+ @span.attribute("data-type").value.should == "input"
250
+ end
251
+
252
+ it "should have no data-collection" do
253
+ @span.attribute("data-collection").should be_nil
254
+ end
255
+ end
256
+
257
+ context "with a date attribute" do
258
+ before do
259
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :birth_date, :type => :date)
260
+ @span = nk.css("span")
261
+ end
262
+
263
+ it "should render the date as text" do
264
+ @span.text.should == @user.birth_date.to_date.to_s
265
+ end
266
+
267
+ it "should have a date data-type" do
268
+ @span.attribute("data-type").value.should == "date"
269
+ end
270
+
271
+ it "should have no data-collection" do
272
+ @span.attribute("data-collection").should be_nil
273
+ end
274
+ end
275
+
276
+ context "with a boolean attribute" do
277
+ before do
278
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :type => :checkbox)
279
+ @span = nk.css("span")
280
+ end
281
+
282
+ it "should have a checkbox data-type" do
283
+ @span.attribute("data-type").value.should == "checkbox"
284
+ end
285
+
286
+ it "should have the default data-collection" do
287
+ data = ["No", "Yes"]
288
+ @span.attribute("data-collection").value.should == data.to_json
289
+ end
290
+
291
+ it "should render the current option as No" do
292
+ @span.text.should == "No"
293
+ end
294
+
295
+ describe "custom collection" do
296
+ before do
297
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :type => :checkbox, :collection => ["Nain", "Da"])
298
+ @span = nk.css("span")
299
+ end
300
+
301
+ it "should show the message with the custom values" do
302
+ @span.text.should == "Nain"
303
+ end
304
+
305
+ it "should render the proper data-collection" do
306
+ @span.attribute("data-collection").value.should == ["Nain", "Da"].to_json
307
+ end
308
+ end
309
+
310
+ end
311
+
312
+ context "with a select attribute" do
313
+ before do
314
+ @countries = COUNTRIES.to_a
315
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @countries)
316
+ @span = nk.css("span")
317
+ end
318
+
319
+ it "should have a select data-type" do
320
+ @span.attribute("data-type").value.should == "select"
321
+ end
322
+
323
+ it "should have a proper data collection" do
324
+ @span.attribute("data-collection").value.should == @countries.to_json
325
+ end
326
+
327
+ it "should show the current country" do
328
+ @span.text.should == "Italy"
329
+ end
330
+
331
+ it "should include the proper data-value" do
332
+ @span.attribute("data-value").value.should == "2"
333
+ end
334
+
335
+ context "with an apostrophe in it" do
336
+ before do
337
+ @apostrophe_countries = [[1, "Joe's Country"], [2, "Bob's Country"]]
338
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @apostrophe_countries)
339
+ @span = nk.css("span")
340
+ end
341
+
342
+ it "should have a proper data collection" do
343
+ @span.attribute("data-collection").value.should == @apostrophe_countries.to_json
344
+ end
345
+ end
346
+ end
347
+ end
348
+
349
+ describe "#best_in_place_if" do
350
+ context "when the parameters are valid" do
351
+ before do
352
+ @user = User.new :name => "Lucia",
353
+ :last_name => "Napoli",
354
+ :email => "lucianapoli@gmail.com",
355
+ :height => "5' 5\"",
356
+ :address => "Via Roma 99",
357
+ :zip => "25123",
358
+ :country => "2",
359
+ :receive_email => false,
360
+ :birth_date => Time.now.utc.to_date,
361
+ :description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
362
+ :money => 150
363
+ @options = {}
364
+ end
365
+
366
+ context "when the condition is true" do
367
+ before {@condition = true}
368
+
369
+ it "should work with array-like objects in order to provide support to namespaces" do
370
+ nk = Nokogiri::HTML.parse(helper.best_in_place_if @condition, [:admin, @user], :name)
371
+ span = nk.css("span")
372
+ span.text.should == "Lucia"
373
+ end
374
+
375
+ context "when the options parameter is left off" do
376
+ it "should call best_in_place with the rest of the parameters and empty options" do
377
+ helper.should_receive(:best_in_place).with(@user, :name, {})
378
+ helper.best_in_place_if @condition, @user, :name
379
+ end
380
+ end
381
+
382
+ context "when the options parameter is included" do
383
+ it "should call best_in_place with the rest of the parameters" do
384
+ helper.should_receive(:best_in_place).with(@user, :name, @options)
385
+ helper.best_in_place_if @condition, @user, :name, @options
386
+ end
387
+ end
388
+ end
389
+
390
+ context "when the condition is false" do
391
+ before {@condition = false}
392
+
393
+ it "should work with array-like objects in order to provide support to namespaces" do
394
+ helper.best_in_place_if(@condition, [:admin, @user], :name).should eq "Lucia"
395
+ end
396
+
397
+ it "should return the value of the field when the options value is left off" do
398
+ helper.best_in_place_if(@condition, @user, :name).should eq "Lucia"
399
+ end
400
+
401
+ it "should return the value of the field when the options value is included" do
402
+ helper.best_in_place_if(@condition, @user, :name, @options).should eq "Lucia"
403
+ end
404
+ end
405
+ end
406
+ end
407
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ describe "Double initialization bug", :js => true do
5
+ before do
6
+ @user = User.new :name => "Lucia",
7
+ :last_name => "Napoli",
8
+ :email => "lucianapoli@gmail.com",
9
+ :height => "5' 5\"",
10
+ :address => "Via Roma 99",
11
+ :zip => "25123",
12
+ :country => "2",
13
+ :receive_email => false,
14
+ :description => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a lectus et lacus ultrices auctor. Morbi aliquet convallis tincidunt. Praesent enim libero, iaculis at commodo nec, fermentum a dolor. Quisque eget eros id felis lacinia faucibus feugiat et ante. Aenean justo nisi, aliquam vel egestas vel, porta in ligula. Etiam molestie, lacus eget tincidunt accumsan, elit justo rhoncus urna, nec pretium neque mi et lorem. Aliquam posuere, dolor quis pulvinar luctus, felis dolor tincidunt leo, eget pretium orci purus ac nibh. Ut enim sem, suscipit ac elementum vitae, sodales vel sem.",
15
+ :money => 100
16
+ end
17
+
18
+ it "should be able to change a boolean value" do
19
+ @user.save!
20
+ visit double_init_user_path(@user)
21
+
22
+ within("#receive_email") do
23
+ page.should have_content("No thanks")
24
+ end
25
+
26
+ bip_bool @user, :receive_email
27
+
28
+ visit double_init_user_path(@user)
29
+ within("#receive_email") do
30
+ page.should have_content("Yes of course")
31
+ end
32
+
33
+ end
34
+ end