crest_in_place 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile +9 -0
- data/README.md +440 -0
- data/Rakefile +8 -0
- data/crest_in_place-2.1.0.gem +0 -0
- data/crest_in_place.gemspec +28 -0
- data/lib/assets/javascripts/best_in_place.js +740 -0
- data/lib/assets/javascripts/best_in_place.purr.js +10 -0
- data/lib/assets/javascripts/jquery.purr.js +135 -0
- data/lib/crest_in_place.rb +12 -0
- data/lib/crest_in_place/check_version.rb +8 -0
- data/lib/crest_in_place/controller_extensions.rb +28 -0
- data/lib/crest_in_place/display_methods.rb +44 -0
- data/lib/crest_in_place/engine.rb +8 -0
- data/lib/crest_in_place/helper.rb +132 -0
- data/lib/crest_in_place/railtie.rb +7 -0
- data/lib/crest_in_place/test_helpers.rb +42 -0
- data/lib/crest_in_place/utils.rb +21 -0
- data/lib/crest_in_place/version.rb +3 -0
- data/spec/helpers/best_in_place_spec.rb +429 -0
- data/spec/integration/double_init_spec.rb +34 -0
- data/spec/integration/js_spec.rb +1041 -0
- data/spec/integration/live_spec.rb +40 -0
- data/spec/integration/text_area_spec.rb +40 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/retry_on_timeout.rb +10 -0
- data/test_app/Gemfile +16 -0
- data/test_app/README +256 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/assets/images/no.png +0 -0
- data/test_app/app/assets/images/red_pen.png +0 -0
- data/test_app/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/test_app/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/test_app/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/test_app/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/test_app/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/test_app/app/assets/images/ui-icons_222222_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/test_app/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/test_app/app/assets/images/yes.png +0 -0
- data/test_app/app/assets/javascripts/application.js +35 -0
- data/test_app/app/assets/stylesheets/.gitkeep +0 -0
- data/test_app/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +357 -0
- data/test_app/app/assets/stylesheets/scaffold.css +60 -0
- data/test_app/app/assets/stylesheets/style.css.erb +87 -0
- data/test_app/app/controllers/admin/users_controller.rb +14 -0
- data/test_app/app/controllers/application_controller.rb +3 -0
- data/test_app/app/controllers/cuca/cars_controller.rb +16 -0
- data/test_app/app/controllers/users_controller.rb +99 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/test_app/app/helpers/users_helper.rb +29 -0
- data/test_app/app/models/cuca/car.rb +5 -0
- data/test_app/app/models/user.rb +27 -0
- data/test_app/app/views/admin/users/show.html.erb +20 -0
- data/test_app/app/views/cuca/cars/show.html.erb +13 -0
- data/test_app/app/views/layouts/application.html.erb +14 -0
- data/test_app/app/views/users/_form.html.erb +51 -0
- data/test_app/app/views/users/double_init.html.erb +72 -0
- data/test_app/app/views/users/edit.html.erb +5 -0
- data/test_app/app/views/users/email_field.html.erb +1 -0
- data/test_app/app/views/users/index.html.erb +25 -0
- data/test_app/app/views/users/new.html.erb +5 -0
- data/test_app/app/views/users/show.html.erb +141 -0
- data/test_app/app/views/users/show_ajax.html.erb +12 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/application.rb +51 -0
- data/test_app/config/boot.rb +13 -0
- data/test_app/config/database.yml +22 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +25 -0
- data/test_app/config/environments/production.rb +49 -0
- data/test_app/config/environments/test.rb +35 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/countries.rb +1 -0
- data/test_app/config/initializers/default_date_format.rb +2 -0
- data/test_app/config/initializers/inflections.rb +10 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/routes.rb +20 -0
- data/test_app/db/migrate/20101206205922_create_users.rb +18 -0
- data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +9 -0
- data/test_app/db/migrate/20110115204441_add_description_to_user.rb +9 -0
- data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +5 -0
- data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +5 -0
- data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +5 -0
- data/test_app/db/migrate/20111224181356_add_money_to_user.rb +5 -0
- data/test_app/db/migrate/20120513003308_create_cars.rb +11 -0
- data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +5 -0
- data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +6 -0
- data/test_app/db/migrate/20120620165212_add_height_to_user.rb +5 -0
- data/test_app/db/migrate/20130213224102_add_favorite_locale_to_users.rb +5 -0
- data/test_app/db/schema.rb +41 -0
- data/test_app/db/seeds.rb +19 -0
- data/test_app/doc/README_FOR_APP +2 -0
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/lib/tasks/cron.rake +7 -0
- data/test_app/public/404.html +26 -0
- data/test_app/public/422.html +26 -0
- data/test_app/public/500.html +26 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/script/rails +6 -0
- data/test_app/test/fixtures/users.yml +17 -0
- data/test_app/test/functional/users_controller_test.rb +49 -0
- data/test_app/test/performance/browsing_test.rb +9 -0
- data/test_app/test/test_helper.rb +13 -0
- data/test_app/test/unit/helpers/users_helper_test.rb +4 -0
- data/test_app/test/unit/user_test.rb +8 -0
- data/test_app/vendor/plugins/.gitkeep +0 -0
- metadata +256 -0
@@ -0,0 +1,429 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe CrestInPlace::CrestInPlaceHelpers 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 OK button class by default" do
|
79
|
+
@span.attribute("data-ok-button-class").should be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should have no Cancel button text by default" do
|
83
|
+
@span.attribute("data-cancel-button").should be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should have no Cancel button class by default" do
|
87
|
+
@span.attribute("data-cancel-button-class").should be_nil
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should have no Use-Confirmation dialog option by default" do
|
91
|
+
@span.attribute("data-use-confirm").should be_nil
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should have no inner_class by default" do
|
95
|
+
@span.attribute("data-inner-class").should be_nil
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "url generation" do
|
99
|
+
it "should have the correct default url" do
|
100
|
+
@user.save!
|
101
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
102
|
+
span = nk.css("span")
|
103
|
+
span.attribute("data-url").value.should == "/users/#{@user.id}"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should use the custom url specified in string format" do
|
107
|
+
out = helper.best_in_place @user, :name, :path => "/custom/path"
|
108
|
+
nk = Nokogiri::HTML.parse(out)
|
109
|
+
span = nk.css("span")
|
110
|
+
span.attribute("data-url").value.should == "/custom/path"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should use the path given in a named_path format" do
|
114
|
+
out = helper.best_in_place @user, :name, :path => helper.users_path
|
115
|
+
nk = Nokogiri::HTML.parse(out)
|
116
|
+
span = nk.css("span")
|
117
|
+
span.attribute("data-url").value.should == "/users"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should use the given path in a hash format" do
|
121
|
+
out = helper.best_in_place @user, :name, :path => {:controller => :users, :action => :edit, :id => 23}
|
122
|
+
nk = Nokogiri::HTML.parse(out)
|
123
|
+
span = nk.css("span")
|
124
|
+
span.attribute("data-url").value.should == "/users/23/edit"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "nil option" do
|
129
|
+
it "should have no nil data by default" do
|
130
|
+
@span.attribute("data-nil").should be_nil
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should show '' if the object responds with nil for the passed attribute" do
|
134
|
+
@user.stub!(:name).and_return(nil)
|
135
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
136
|
+
span = nk.css("span")
|
137
|
+
span.text.should == ""
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should show '' if the object responds with an empty string for the passed attribute" do
|
141
|
+
@user.stub!(:name).and_return("")
|
142
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
143
|
+
span = nk.css("span")
|
144
|
+
span.text.should == ""
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should have the given inner_class" do
|
149
|
+
out = helper.best_in_place @user, :name, :inner_class => "awesome"
|
150
|
+
nk = Nokogiri::HTML.parse(out)
|
151
|
+
span = nk.css("span")
|
152
|
+
span.attribute("data-inner-class").value.should == "awesome"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should have the given activator" do
|
156
|
+
out = helper.best_in_place @user, :name, :activator => "awesome"
|
157
|
+
nk = Nokogiri::HTML.parse(out)
|
158
|
+
span = nk.css("span")
|
159
|
+
span.attribute("data-activator").value.should == "awesome"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should have the given OK button text" do
|
163
|
+
out = helper.best_in_place @user, :name, :ok_button => "okay"
|
164
|
+
nk = Nokogiri::HTML.parse(out)
|
165
|
+
span = nk.css("span")
|
166
|
+
span.attribute("data-ok-button").value.should == "okay"
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should have the given OK button class" do
|
170
|
+
out = helper.best_in_place @user, :name, :ok_button => "okay", :ok_button_class => "okay-class"
|
171
|
+
nk = Nokogiri::HTML.parse(out)
|
172
|
+
span = nk.css("span")
|
173
|
+
span.attribute("data-ok-button-class").value.should == "okay-class"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should have the given Cancel button text" do
|
177
|
+
out = helper.best_in_place @user, :name, :cancel_button => "nasty"
|
178
|
+
nk = Nokogiri::HTML.parse(out)
|
179
|
+
span = nk.css("span")
|
180
|
+
span.attribute("data-cancel-button").value.should == "nasty"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should have the given Cancel button class" do
|
184
|
+
out = helper.best_in_place @user, :name, :cancel_button => "nasty", :cancel_button_class => "nasty-class"
|
185
|
+
nk = Nokogiri::HTML.parse(out)
|
186
|
+
span = nk.css("span")
|
187
|
+
span.attribute("data-cancel-button-class").value.should == "nasty-class"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should have the given Use-Confirmation dialog option" do
|
191
|
+
out = helper.best_in_place @user, :name, :use_confirm => "false"
|
192
|
+
nk = Nokogiri::HTML.parse(out)
|
193
|
+
span = nk.css("span")
|
194
|
+
span.attribute("data-use-confirm").value.should == "false"
|
195
|
+
end
|
196
|
+
|
197
|
+
describe "object_name" do
|
198
|
+
it "should change the data-object value" do
|
199
|
+
out = helper.best_in_place @user, :name, :object_name => "my_user"
|
200
|
+
nk = Nokogiri::HTML.parse(out)
|
201
|
+
span = nk.css("span")
|
202
|
+
span.attribute("data-object").value.should == "my_user"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should have html5 data attributes" do
|
207
|
+
out = helper.best_in_place @user, :name, :data => { :foo => "awesome", :bar => "nasty" }
|
208
|
+
nk = Nokogiri::HTML.parse(out)
|
209
|
+
span = nk.css("span")
|
210
|
+
span.attribute("data-foo").value.should == "awesome"
|
211
|
+
span.attribute("data-bar").value.should == "nasty"
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "display_as" do
|
215
|
+
it "should render the address with a custom renderer" do
|
216
|
+
@user.should_receive(:address_format).and_return("the result")
|
217
|
+
out = helper.best_in_place @user, :address, :display_as => :address_format
|
218
|
+
nk = Nokogiri::HTML.parse(out)
|
219
|
+
span = nk.css("span")
|
220
|
+
span.text.should == "the result"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "display_with" do
|
225
|
+
it "should render the money with the given view helper" do
|
226
|
+
out = helper.best_in_place @user, :money, :display_with => :number_to_currency
|
227
|
+
nk = Nokogiri::HTML.parse(out)
|
228
|
+
span = nk.css("span")
|
229
|
+
span.text.should == "$150.00"
|
230
|
+
end
|
231
|
+
|
232
|
+
it "accepts a proc" do
|
233
|
+
out = helper.best_in_place @user, :name, :display_with => Proc.new { |v| v.upcase }
|
234
|
+
nk = Nokogiri::HTML.parse(out)
|
235
|
+
span = nk.css("span")
|
236
|
+
span.text.should == "LUCIA"
|
237
|
+
end
|
238
|
+
|
239
|
+
it "should raise an error if the given helper can't be found" do
|
240
|
+
lambda { helper.best_in_place @user, :money, :display_with => :fk_number_to_currency }.should raise_error(ArgumentError)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should call the helper method with the given arguments" do
|
244
|
+
out = helper.best_in_place @user, :money, :display_with => :number_to_currency, :helper_options => {:unit => "º"}
|
245
|
+
nk = Nokogiri::HTML.parse(out)
|
246
|
+
span = nk.css("span")
|
247
|
+
span.text.should == "º150.00"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
describe "array-like objects" do
|
252
|
+
it "should work with array-like objects in order to provide support to namespaces" do
|
253
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @user], :name)
|
254
|
+
span = nk.css("span")
|
255
|
+
span.text.should == "Lucia"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
context "with a text field attribute" do
|
261
|
+
before do
|
262
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
263
|
+
@span = nk.css("span")
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should render the name as text" do
|
267
|
+
@span.text.should == "Lucia"
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should have an input data-type" do
|
271
|
+
@span.attribute("data-type").value.should == "input"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should have no data-collection" do
|
275
|
+
@span.attribute("data-collection").should be_nil
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context "with a date attribute" do
|
280
|
+
before do
|
281
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :birth_date, :type => :date)
|
282
|
+
@span = nk.css("span")
|
283
|
+
end
|
284
|
+
|
285
|
+
it "should render the date as text" do
|
286
|
+
@span.text.should == @user.birth_date.to_date.to_s
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should have a date data-type" do
|
290
|
+
@span.attribute("data-type").value.should == "date"
|
291
|
+
end
|
292
|
+
|
293
|
+
it "should have no data-collection" do
|
294
|
+
@span.attribute("data-collection").should be_nil
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "with a boolean attribute" do
|
299
|
+
before do
|
300
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :type => :checkbox)
|
301
|
+
@span = nk.css("span")
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should have a checkbox data-type" do
|
305
|
+
@span.attribute("data-type").value.should == "checkbox"
|
306
|
+
end
|
307
|
+
|
308
|
+
it "should have the default data-collection" do
|
309
|
+
data = ["No", "Yes"]
|
310
|
+
@span.attribute("data-collection").value.should == data.to_json
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should render the current option as No" do
|
314
|
+
@span.text.should == "No"
|
315
|
+
end
|
316
|
+
|
317
|
+
describe "custom collection" do
|
318
|
+
before do
|
319
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :type => :checkbox, :collection => ["Nain", "Da"])
|
320
|
+
@span = nk.css("span")
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should show the message with the custom values" do
|
324
|
+
@span.text.should == "Nain"
|
325
|
+
end
|
326
|
+
|
327
|
+
it "should render the proper data-collection" do
|
328
|
+
@span.attribute("data-collection").value.should == ["Nain", "Da"].to_json
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
context "with a select attribute" do
|
335
|
+
before do
|
336
|
+
@countries = COUNTRIES.to_a
|
337
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @countries)
|
338
|
+
@span = nk.css("span")
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should have a select data-type" do
|
342
|
+
@span.attribute("data-type").value.should == "select"
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should have a proper data collection" do
|
346
|
+
@span.attribute("data-collection").value.should == @countries.to_json
|
347
|
+
end
|
348
|
+
|
349
|
+
it "should show the current country" do
|
350
|
+
@span.text.should == "Italy"
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should include the proper data-value" do
|
354
|
+
@span.attribute("data-value").value.should == "2"
|
355
|
+
end
|
356
|
+
|
357
|
+
context "with an apostrophe in it" do
|
358
|
+
before do
|
359
|
+
@apostrophe_countries = [[1, "Joe's Country"], [2, "Bob's Country"]]
|
360
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @apostrophe_countries)
|
361
|
+
@span = nk.css("span")
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should have a proper data collection" do
|
365
|
+
@span.attribute("data-collection").value.should == @apostrophe_countries.to_json
|
366
|
+
end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "#best_in_place_if" do
|
372
|
+
context "when the parameters are valid" do
|
373
|
+
before do
|
374
|
+
@user = User.new :name => "Lucia",
|
375
|
+
:last_name => "Napoli",
|
376
|
+
:email => "lucianapoli@gmail.com",
|
377
|
+
:height => "5' 5\"",
|
378
|
+
:address => "Via Roma 99",
|
379
|
+
:zip => "25123",
|
380
|
+
:country => "2",
|
381
|
+
:receive_email => false,
|
382
|
+
:birth_date => Time.now.utc.to_date,
|
383
|
+
: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.",
|
384
|
+
:money => 150
|
385
|
+
@options = {}
|
386
|
+
end
|
387
|
+
|
388
|
+
context "when the condition is true" do
|
389
|
+
before {@condition = true}
|
390
|
+
|
391
|
+
it "should work with array-like objects in order to provide support to namespaces" do
|
392
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place_if @condition, [:admin, @user], :name)
|
393
|
+
span = nk.css("span")
|
394
|
+
span.text.should == "Lucia"
|
395
|
+
end
|
396
|
+
|
397
|
+
context "when the options parameter is left off" do
|
398
|
+
it "should call best_in_place with the rest of the parameters and empty options" do
|
399
|
+
helper.should_receive(:best_in_place).with(@user, :name, {})
|
400
|
+
helper.best_in_place_if @condition, @user, :name
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
context "when the options parameter is included" do
|
405
|
+
it "should call best_in_place with the rest of the parameters" do
|
406
|
+
helper.should_receive(:best_in_place).with(@user, :name, @options)
|
407
|
+
helper.best_in_place_if @condition, @user, :name, @options
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
context "when the condition is false" do
|
413
|
+
before {@condition = false}
|
414
|
+
|
415
|
+
it "should work with array-like objects in order to provide support to namespaces" do
|
416
|
+
helper.best_in_place_if(@condition, [:admin, @user], :name).should eq "Lucia"
|
417
|
+
end
|
418
|
+
|
419
|
+
it "should return the value of the field when the options value is left off" do
|
420
|
+
helper.best_in_place_if(@condition, @user, :name).should eq "Lucia"
|
421
|
+
end
|
422
|
+
|
423
|
+
it "should return the value of the field when the options value is included" do
|
424
|
+
helper.best_in_place_if(@condition, @user, :name, @options).should eq "Lucia"
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
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
|