best_in_place 2.1.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -5
- data/.rspec +1 -0
- data/.travis.yml +12 -5
- data/Appraisals +17 -0
- data/CHANGELOG.md +51 -30
- data/Gemfile +15 -2
- data/README.md +52 -105
- data/best_in_place.gemspec +13 -11
- data/config.ru +7 -0
- data/gemfiles/rails_3.2.gemfile +24 -0
- data/gemfiles/rails_4.0.gemfile +23 -0
- data/gemfiles/rails_4.1.gemfile +23 -0
- data/gemfiles/rails_edge.gemfile +25 -0
- data/lib/assets/javascripts/best_in_place.jquery-ui.js +57 -0
- data/lib/assets/javascripts/best_in_place.js +551 -650
- data/lib/assets/javascripts/best_in_place.purr.js +16 -6
- data/lib/best_in_place.rb +29 -9
- data/lib/best_in_place/controller_extensions.rb +10 -13
- data/lib/best_in_place/display_methods.rb +26 -21
- data/lib/best_in_place/engine.rb +2 -2
- data/lib/best_in_place/helper.rb +145 -87
- data/lib/best_in_place/railtie.rb +5 -2
- data/lib/best_in_place/test_helpers.rb +0 -1
- data/lib/best_in_place/utils.rb +20 -12
- data/lib/best_in_place/version.rb +1 -1
- data/spec/{helpers/best_in_place_spec.rb → helper_spec.rb} +134 -99
- data/spec/integration/double_init_spec.rb +3 -5
- data/spec/integration/js_spec.rb +193 -123
- data/spec/integration/live_spec.rb +3 -4
- data/spec/integration/text_area_spec.rb +4 -4
- data/spec/internal/app/assets/images/info.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/no.png +0 -0
- data/spec/internal/app/assets/images/purrBottom.png +0 -0
- data/spec/internal/app/assets/images/purrClose.png +0 -0
- data/spec/internal/app/assets/images/purrTop.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/red_pen.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_222222_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/{test_app → spec/internal}/app/assets/images/yes.png +0 -0
- data/spec/internal/app/assets/javascripts/application.js +37 -0
- data/{test_app → spec/internal}/app/assets/stylesheets/.gitkeep +0 -0
- data/{test_app → spec/internal}/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +1 -2
- data/{test_app → spec/internal}/app/assets/stylesheets/scaffold.css +1 -1
- data/{test_app → spec/internal}/app/assets/stylesheets/style.css.erb +2 -4
- data/{test_app → spec/internal}/app/controllers/admin/users_controller.rb +8 -3
- data/{test_app → spec/internal}/app/controllers/application_controller.rb +0 -0
- data/{test_app → spec/internal}/app/controllers/cuca/cars_controller.rb +0 -0
- data/{test_app → spec/internal}/app/controllers/users_controller.rb +8 -40
- data/{test_app → spec/internal}/app/helpers/application_helper.rb +0 -0
- data/spec/internal/app/helpers/users_helper.rb +29 -0
- data/{test_app → spec/internal}/app/models/cuca/car.rb +0 -0
- data/{test_app → spec/internal}/app/models/user.rb +5 -1
- data/{test_app → spec/internal}/app/views/admin/users/show.html.erb +2 -2
- data/{test_app → spec/internal}/app/views/cuca/cars/show.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/layouts/application.html.erb +1 -1
- data/{test_app → spec/internal}/app/views/users/_form.html.erb +2 -2
- data/{test_app → spec/internal}/app/views/users/double_init.html.erb +4 -10
- data/spec/internal/app/views/users/edit.html.erb +5 -0
- data/{test_app → spec/internal}/app/views/users/email_field.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/index.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/new.html.erb +0 -0
- data/{test_app → spec/internal}/app/views/users/show.html.erb +32 -24
- data/{test_app → spec/internal}/app/views/users/show_ajax.html.erb +0 -0
- data/spec/internal/config/database.yml +5 -0
- data/{test_app → spec/internal}/config/initializers/countries.rb +0 -0
- data/{test_app → spec/internal}/config/initializers/default_date_format.rb +0 -0
- data/spec/internal/config/initializers/development.rb +8 -0
- data/{test_app → spec/internal}/config/routes.rb +1 -2
- data/spec/internal/db/schema.rb +26 -0
- data/{test_app → spec/internal}/public/favicon.ico +0 -0
- data/spec/rails_helper.rb +21 -0
- data/spec/support/retry_on_timeout.rb +4 -7
- data/spec/utils_spec.rb +21 -0
- data/vendor/assets/javascripts/jquery.autosize.js +272 -0
- data/{lib → vendor}/assets/javascripts/jquery.purr.js +1 -1
- metadata +92 -175
- data/lib/best_in_place/check_version.rb +0 -8
- data/spec/spec_helper.rb +0 -23
- data/test_app/Gemfile +0 -16
- data/test_app/README +0 -256
- data/test_app/Rakefile +0 -7
- data/test_app/app/assets/javascripts/application.js +0 -35
- data/test_app/app/helpers/users_helper.rb +0 -29
- data/test_app/config.ru +0 -4
- data/test_app/config/application.rb +0 -51
- data/test_app/config/boot.rb +0 -13
- data/test_app/config/database.yml +0 -22
- data/test_app/config/environment.rb +0 -5
- data/test_app/config/environments/development.rb +0 -25
- data/test_app/config/environments/production.rb +0 -49
- data/test_app/config/environments/test.rb +0 -35
- data/test_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test_app/config/initializers/inflections.rb +0 -10
- data/test_app/config/initializers/mime_types.rb +0 -5
- data/test_app/config/initializers/secret_token.rb +0 -7
- data/test_app/config/initializers/session_store.rb +0 -8
- data/test_app/config/locales/en.yml +0 -5
- data/test_app/db/migrate/20101206205922_create_users.rb +0 -18
- data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +0 -9
- data/test_app/db/migrate/20110115204441_add_description_to_user.rb +0 -9
- data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +0 -5
- data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +0 -5
- data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +0 -5
- data/test_app/db/migrate/20111224181356_add_money_to_user.rb +0 -5
- data/test_app/db/migrate/20120513003308_create_cars.rb +0 -11
- data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +0 -5
- data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +0 -6
- data/test_app/db/migrate/20120620165212_add_height_to_user.rb +0 -5
- data/test_app/db/migrate/20130213224102_add_favorite_locale_to_users.rb +0 -5
- data/test_app/db/schema.rb +0 -41
- data/test_app/db/seeds.rb +0 -19
- data/test_app/doc/README_FOR_APP +0 -2
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/lib/tasks/cron.rake +0 -7
- data/test_app/public/404.html +0 -26
- data/test_app/public/422.html +0 -26
- data/test_app/public/500.html +0 -26
- data/test_app/public/robots.txt +0 -5
- data/test_app/script/rails +0 -6
- data/test_app/test/fixtures/users.yml +0 -17
- data/test_app/test/functional/users_controller_test.rb +0 -49
- data/test_app/test/performance/browsing_test.rb +0 -9
- data/test_app/test/test_helper.rb +0 -13
- data/test_app/test/unit/helpers/users_helper_test.rb +0 -4
- data/test_app/test/unit/user_test.rb +0 -8
- data/test_app/vendor/plugins/.gitkeep +0 -0
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'action_view/base'
|
3
|
+
|
1
4
|
module BestInPlace
|
2
|
-
class Railtie < Rails::Railtie
|
3
|
-
|
5
|
+
class Railtie < ::Rails::Railtie #:nodoc:
|
6
|
+
config.after_initialize do
|
4
7
|
BestInPlace::ViewHelpers = ActionView::Base.new
|
5
8
|
end
|
6
9
|
end
|
data/lib/best_in_place/utils.rb
CHANGED
@@ -1,21 +1,29 @@
|
|
1
1
|
module BestInPlace
|
2
|
-
module Utils
|
3
|
-
|
4
|
-
|
2
|
+
module Utils #:nodoc:
|
3
|
+
module_function
|
5
4
|
def build_best_in_place_id(object, field)
|
6
|
-
|
7
|
-
|
5
|
+
case object
|
6
|
+
when Symbol, String
|
7
|
+
"best_in_place_#{object}_#{field}"
|
8
|
+
else
|
9
|
+
id = "best_in_place_#{object_to_key(object)}"
|
10
|
+
id << "_#{object.id}" if object.persisted?
|
11
|
+
id << "_#{field}"
|
12
|
+
id
|
8
13
|
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
14
|
end
|
15
15
|
|
16
16
|
def object_to_key(object)
|
17
|
-
|
18
|
-
|
17
|
+
model_name_from_record_or_class(object).param_key
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert_to_model(object)
|
21
|
+
object.respond_to?(:to_model) ? object.to_model : object
|
19
22
|
end
|
23
|
+
|
24
|
+
def model_name_from_record_or_class(record_or_class)
|
25
|
+
(record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name
|
26
|
+
end
|
27
|
+
|
20
28
|
end
|
21
29
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require "spec_helper"
|
3
2
|
|
4
|
-
describe BestInPlace::
|
3
|
+
describe BestInPlace::Helper, type: :helper do
|
5
4
|
describe "#best_in_place" do
|
6
5
|
before do
|
6
|
+
|
7
7
|
@user = User.new :name => "Lucia",
|
8
8
|
:last_name => "Napoli",
|
9
9
|
:email => "lucianapoli@gmail.com",
|
@@ -20,79 +20,77 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
20
20
|
it "should generate a proper id for namespaced models" do
|
21
21
|
@car = Cuca::Car.create :model => "Ford"
|
22
22
|
|
23
|
-
nk = Nokogiri::HTML.parse(helper.best_in_place @car, :model, :
|
23
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @car, :model, url: helper.cuca_cars_path)
|
24
24
|
span = nk.css("span")
|
25
|
-
span.attribute("id").value.
|
25
|
+
expect(span.attribute("id").value).to eq("best_in_place_cuca_car_#{@car.id}_model")
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should generate a proper span" do
|
29
29
|
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
30
30
|
span = nk.css("span")
|
31
|
-
span.
|
31
|
+
expect(span).not_to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should not allow both display_as and display_with option" do
|
35
|
-
|
35
|
+
expect { helper.best_in_place(@user, :money, :display_with => :number_to_currency, :display_as => :custom) }.to raise_error(ArgumentError)
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "general properties" do
|
39
39
|
before do
|
40
|
+
@user.save
|
40
41
|
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
41
42
|
@span = nk.css("span")
|
42
43
|
end
|
43
44
|
|
44
45
|
context "when it's an ActiveRecord model" do
|
45
46
|
it "should have a proper id" do
|
46
|
-
@span.attribute("id").value.
|
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"
|
47
|
+
expect(@span.attribute("id").value).to eq("best_in_place_user_#{@user.id}_name")
|
55
48
|
end
|
56
49
|
end
|
57
50
|
|
58
51
|
it "should have the best_in_place class" do
|
59
|
-
@span.attribute("class").value.
|
52
|
+
expect(@span.attribute("class").value).to eq("best_in_place")
|
60
53
|
end
|
61
54
|
|
62
|
-
it "should have the correct data-attribute" do
|
63
|
-
@span.attribute("data-attribute").value.
|
55
|
+
it "should have the correct data-bip-attribute" do
|
56
|
+
expect(@span.attribute("data-bip-attribute").value).to eq("name")
|
64
57
|
end
|
65
58
|
|
66
|
-
it "should have the correct data-object" do
|
67
|
-
@span.attribute("data-object").value.
|
59
|
+
it "should have the correct data-bip-object" do
|
60
|
+
expect(@span.attribute("data-bip-object").value).to eq("user")
|
68
61
|
end
|
69
62
|
|
70
63
|
it "should have no activator by default" do
|
71
|
-
@span.attribute("data-activator").
|
64
|
+
expect(@span.attribute("data-bip-activator")).to be_nil
|
72
65
|
end
|
73
66
|
|
74
67
|
it "should have no OK button text by default" do
|
75
|
-
@span.attribute("data-ok-button").
|
68
|
+
expect(@span.attribute("data-bip-ok-button")).to be_nil
|
76
69
|
end
|
77
70
|
|
78
71
|
it "should have no OK button class by default" do
|
79
|
-
@span.attribute("data-ok-button-class").
|
72
|
+
expect(@span.attribute("data-bip-ok-button-class")).to be_nil
|
80
73
|
end
|
81
74
|
|
82
75
|
it "should have no Cancel button text by default" do
|
83
|
-
@span.attribute("data-cancel-button").
|
76
|
+
expect(@span.attribute("data-bip-cancel-button")).to be_nil
|
84
77
|
end
|
85
78
|
|
86
79
|
it "should have no Cancel button class by default" do
|
87
|
-
@span.attribute("data-cancel-button-class").
|
80
|
+
expect(@span.attribute("data-bip-cancel-button-class")).to be_nil
|
88
81
|
end
|
89
82
|
|
90
83
|
it "should have no Use-Confirmation dialog option by default" do
|
91
|
-
@span.attribute("data-
|
84
|
+
expect(@span.attribute("data-bip-confirm")).to be_nil
|
92
85
|
end
|
93
86
|
|
94
87
|
it "should have no inner_class by default" do
|
95
|
-
@span.attribute("data-inner-class").
|
88
|
+
expect(@span.attribute("data-bip-inner-class")).to be_nil
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
it "should have be sanitized by default" do
|
93
|
+
expect(@span.attribute("data-bip-raw")).to be_nil
|
96
94
|
end
|
97
95
|
|
98
96
|
describe "url generation" do
|
@@ -100,48 +98,48 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
100
98
|
@user.save!
|
101
99
|
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
102
100
|
span = nk.css("span")
|
103
|
-
span.attribute("data-url").value.
|
101
|
+
expect(span.attribute("data-bip-url").value).to eq("/users/#{@user.id}")
|
104
102
|
end
|
105
103
|
|
106
104
|
it "should use the custom url specified in string format" do
|
107
|
-
out = helper.best_in_place @user, :name, :
|
105
|
+
out = helper.best_in_place @user, :name, url: "/custom/path"
|
108
106
|
nk = Nokogiri::HTML.parse(out)
|
109
107
|
span = nk.css("span")
|
110
|
-
span.attribute("data-url").value.
|
108
|
+
expect(span.attribute("data-bip-url").value).to eq("/custom/path")
|
111
109
|
end
|
112
110
|
|
113
111
|
it "should use the path given in a named_path format" do
|
114
|
-
out = helper.best_in_place @user, :name, :
|
112
|
+
out = helper.best_in_place @user, :name, url: helper.users_path
|
115
113
|
nk = Nokogiri::HTML.parse(out)
|
116
114
|
span = nk.css("span")
|
117
|
-
span.attribute("data-url").value.
|
115
|
+
expect(span.attribute("data-bip-url").value).to eq("/users")
|
118
116
|
end
|
119
117
|
|
120
118
|
it "should use the given path in a hash format" do
|
121
|
-
out = helper.best_in_place @user, :name, :
|
119
|
+
out = helper.best_in_place @user, :name, url: {:controller => :users, :action => :edit, :id => 23}
|
122
120
|
nk = Nokogiri::HTML.parse(out)
|
123
121
|
span = nk.css("span")
|
124
|
-
span.attribute("data-url").value.
|
122
|
+
expect(span.attribute("data-bip-url").value).to eq("/users/23/edit")
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
128
126
|
describe "nil option" do
|
129
127
|
it "should have no nil data by default" do
|
130
|
-
@span.attribute("data-
|
128
|
+
expect(@span.attribute("data-bip-placeholder")).to be_nil
|
131
129
|
end
|
132
130
|
|
133
131
|
it "should show '' if the object responds with nil for the passed attribute" do
|
134
|
-
@user.
|
132
|
+
expect(@user).to receive(:name).twice.and_return("")
|
135
133
|
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
136
134
|
span = nk.css("span")
|
137
|
-
span.text.
|
135
|
+
expect(span.text).to eq("")
|
138
136
|
end
|
139
137
|
|
140
138
|
it "should show '' if the object responds with an empty string for the passed attribute" do
|
141
|
-
@user.
|
139
|
+
expect(@user).to receive(:name).twice.and_return("")
|
142
140
|
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
143
141
|
span = nk.css("span")
|
144
|
-
span.text.
|
142
|
+
expect(span.text).to eq("")
|
145
143
|
end
|
146
144
|
end
|
147
145
|
|
@@ -149,57 +147,72 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
149
147
|
out = helper.best_in_place @user, :name, :inner_class => "awesome"
|
150
148
|
nk = Nokogiri::HTML.parse(out)
|
151
149
|
span = nk.css("span")
|
152
|
-
span.attribute("data-inner-class").value.
|
150
|
+
expect(span.attribute("data-bip-inner-class").value).to eq("awesome")
|
153
151
|
end
|
154
152
|
|
155
153
|
it "should have the given activator" do
|
156
154
|
out = helper.best_in_place @user, :name, :activator => "awesome"
|
157
155
|
nk = Nokogiri::HTML.parse(out)
|
158
156
|
span = nk.css("span")
|
159
|
-
span.attribute("data-activator").value.
|
157
|
+
expect(span.attribute("data-bip-activator").value).to eq("awesome")
|
160
158
|
end
|
161
159
|
|
162
160
|
it "should have the given OK button text" do
|
163
161
|
out = helper.best_in_place @user, :name, :ok_button => "okay"
|
164
162
|
nk = Nokogiri::HTML.parse(out)
|
165
163
|
span = nk.css("span")
|
166
|
-
span.attribute("data-ok-button").value.
|
164
|
+
expect(span.attribute("data-bip-ok-button").value).to eq("okay")
|
167
165
|
end
|
168
166
|
|
169
167
|
it "should have the given OK button class" do
|
170
168
|
out = helper.best_in_place @user, :name, :ok_button => "okay", :ok_button_class => "okay-class"
|
171
169
|
nk = Nokogiri::HTML.parse(out)
|
172
170
|
span = nk.css("span")
|
173
|
-
span.attribute("data-ok-button-class").value.
|
171
|
+
expect(span.attribute("data-bip-ok-button-class").value).to eq("okay-class")
|
174
172
|
end
|
175
173
|
|
176
174
|
it "should have the given Cancel button text" do
|
177
175
|
out = helper.best_in_place @user, :name, :cancel_button => "nasty"
|
178
176
|
nk = Nokogiri::HTML.parse(out)
|
179
177
|
span = nk.css("span")
|
180
|
-
span.attribute("data-cancel-button").value.
|
178
|
+
expect(span.attribute("data-bip-cancel-button").value).to eq("nasty")
|
181
179
|
end
|
182
180
|
|
183
181
|
it "should have the given Cancel button class" do
|
184
182
|
out = helper.best_in_place @user, :name, :cancel_button => "nasty", :cancel_button_class => "nasty-class"
|
185
183
|
nk = Nokogiri::HTML.parse(out)
|
186
184
|
span = nk.css("span")
|
187
|
-
span.attribute("data-cancel-button-class").value.
|
185
|
+
expect(span.attribute("data-bip-cancel-button-class").value).to eq("nasty-class")
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should have the given Confirmation dialog option' do
|
189
|
+
out = helper.best_in_place @user, :name, :confirm => "false"
|
190
|
+
nk = Nokogiri::HTML.parse(out)
|
191
|
+
span = nk.css("span")
|
192
|
+
expect(span.attribute('data-bip-confirm').value).to eq('false')
|
188
193
|
end
|
189
194
|
|
190
|
-
it "should
|
191
|
-
out = helper.best_in_place @user, :name, :
|
195
|
+
it "should be raw" do
|
196
|
+
out = helper.best_in_place @user, :name, raw: true
|
192
197
|
nk = Nokogiri::HTML.parse(out)
|
193
198
|
span = nk.css("span")
|
194
|
-
span.attribute(
|
199
|
+
expect(span.attribute('data-bip-raw').value).to eq('true')
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'should not satinize if raw is true' do
|
203
|
+
@user.description = '<h1>Raw text</h1>'
|
204
|
+
out = helper.best_in_place @user, :description, raw: true
|
205
|
+
nk = Nokogiri::HTML.parse(out)
|
206
|
+
span = nk.css('span')
|
207
|
+
expect(span.css('h1')).to_not be_empty
|
195
208
|
end
|
196
209
|
|
197
210
|
describe "object_name" do
|
198
|
-
it "should change the data-object value" do
|
199
|
-
out = helper.best_in_place @user, :name, :
|
211
|
+
it "should change the data-bip-object value" do
|
212
|
+
out = helper.best_in_place @user, :name, param: "my_user"
|
200
213
|
nk = Nokogiri::HTML.parse(out)
|
201
214
|
span = nk.css("span")
|
202
|
-
span.attribute("data-object").value.
|
215
|
+
expect(span.attribute("data-bip-object").value).to eq("my_user")
|
203
216
|
end
|
204
217
|
end
|
205
218
|
|
@@ -207,17 +220,17 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
207
220
|
out = helper.best_in_place @user, :name, :data => { :foo => "awesome", :bar => "nasty" }
|
208
221
|
nk = Nokogiri::HTML.parse(out)
|
209
222
|
span = nk.css("span")
|
210
|
-
span.attribute("data-foo").value.
|
211
|
-
span.attribute("data-bar").value.
|
223
|
+
expect(span.attribute("data-foo").value).to eq("awesome")
|
224
|
+
expect(span.attribute("data-bar").value).to eq("nasty")
|
212
225
|
end
|
213
226
|
|
214
227
|
describe "display_as" do
|
215
228
|
it "should render the address with a custom renderer" do
|
216
|
-
@user.
|
229
|
+
expect(@user).to receive(:address_format).and_return("the result")
|
217
230
|
out = helper.best_in_place @user, :address, :display_as => :address_format
|
218
231
|
nk = Nokogiri::HTML.parse(out)
|
219
232
|
span = nk.css("span")
|
220
|
-
span.text.
|
233
|
+
expect(span.text).to eq("the result")
|
221
234
|
end
|
222
235
|
end
|
223
236
|
|
@@ -226,25 +239,25 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
226
239
|
out = helper.best_in_place @user, :money, :display_with => :number_to_currency
|
227
240
|
nk = Nokogiri::HTML.parse(out)
|
228
241
|
span = nk.css("span")
|
229
|
-
span.text.
|
242
|
+
expect(span.text).to eq("$150.00")
|
230
243
|
end
|
231
244
|
|
232
245
|
it "accepts a proc" do
|
233
246
|
out = helper.best_in_place @user, :name, :display_with => Proc.new { |v| v.upcase }
|
234
247
|
nk = Nokogiri::HTML.parse(out)
|
235
248
|
span = nk.css("span")
|
236
|
-
span.text.
|
249
|
+
expect(span.text).to eq("LUCIA")
|
237
250
|
end
|
238
251
|
|
239
252
|
it "should raise an error if the given helper can't be found" do
|
240
|
-
|
253
|
+
expect { helper.best_in_place @user, :money, :display_with => :fk_number_to_currency }.to raise_error(ArgumentError)
|
241
254
|
end
|
242
255
|
|
243
256
|
it "should call the helper method with the given arguments" do
|
244
257
|
out = helper.best_in_place @user, :money, :display_with => :number_to_currency, :helper_options => {:unit => "º"}
|
245
258
|
nk = Nokogiri::HTML.parse(out)
|
246
259
|
span = nk.css("span")
|
247
|
-
span.text.
|
260
|
+
expect(span.text).to eq("º150.00")
|
248
261
|
end
|
249
262
|
end
|
250
263
|
|
@@ -252,7 +265,7 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
252
265
|
it "should work with array-like objects in order to provide support to namespaces" do
|
253
266
|
nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @user], :name)
|
254
267
|
span = nk.css("span")
|
255
|
-
span.text.
|
268
|
+
expect(span.text).to eq("Lucia")
|
256
269
|
end
|
257
270
|
end
|
258
271
|
end
|
@@ -264,68 +277,68 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
264
277
|
end
|
265
278
|
|
266
279
|
it "should render the name as text" do
|
267
|
-
@span.text.
|
280
|
+
expect(@span.text).to eq("Lucia")
|
268
281
|
end
|
269
282
|
|
270
|
-
it
|
271
|
-
@span.attribute(
|
283
|
+
it 'should have an input data-bip-type' do
|
284
|
+
expect(@span.attribute('data-bip-type').value).to eq('input')
|
272
285
|
end
|
273
286
|
|
274
|
-
it
|
275
|
-
@span.attribute(
|
287
|
+
it 'should have no data-bip-collection' do
|
288
|
+
expect(@span.attribute('data-bip-collection')).to be_nil
|
276
289
|
end
|
277
290
|
end
|
278
291
|
|
279
292
|
context "with a date attribute" do
|
280
293
|
before do
|
281
|
-
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :birth_date, :
|
294
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :birth_date, as: :date)
|
282
295
|
@span = nk.css("span")
|
283
296
|
end
|
284
297
|
|
285
298
|
it "should render the date as text" do
|
286
|
-
@span.text.
|
299
|
+
expect(@span.text).to eq(@user.birth_date.to_date.to_s)
|
287
300
|
end
|
288
301
|
|
289
|
-
it "should have a date data-type" do
|
290
|
-
@span.attribute("data-type").value.
|
302
|
+
it "should have a date data-bip-type" do
|
303
|
+
expect(@span.attribute("data-bip-type").value).to eq("date")
|
291
304
|
end
|
292
305
|
|
293
|
-
it "should have no data-collection" do
|
294
|
-
@span.attribute("data-collection").
|
306
|
+
it "should have no data-bip-collection" do
|
307
|
+
expect(@span.attribute("data-bip-collection")).to be_nil
|
295
308
|
end
|
296
309
|
end
|
297
310
|
|
298
311
|
context "with a boolean attribute" do
|
299
312
|
before do
|
300
|
-
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :
|
313
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, as: :checkbox)
|
301
314
|
@span = nk.css("span")
|
302
315
|
end
|
303
316
|
|
304
|
-
it "should have a checkbox data-type" do
|
305
|
-
@span.attribute("data-type").value.
|
317
|
+
it "should have a checkbox data-bip-type" do
|
318
|
+
expect(@span.attribute("data-bip-type").value).to eq("checkbox")
|
306
319
|
end
|
307
320
|
|
308
|
-
it "should have the default data-collection" do
|
309
|
-
data
|
310
|
-
@span.attribute("data-collection").value.should == data.to_json
|
321
|
+
it "should have the default data-bip-collection" do
|
322
|
+
expect(@span.attribute("data-bip-collection").value).to eq("{\"true\":\"Yes\",\"false\":\"No\"}")
|
311
323
|
end
|
312
324
|
|
313
325
|
it "should render the current option as No" do
|
314
|
-
@span.text.
|
326
|
+
expect(@span.text).to eq("No")
|
315
327
|
end
|
316
328
|
|
317
329
|
describe "custom collection" do
|
318
330
|
before do
|
319
|
-
|
331
|
+
@collection = {'false' => 'Nain', 'true' => 'Da'}
|
332
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, as: :checkbox, collection: @collection)
|
320
333
|
@span = nk.css("span")
|
321
334
|
end
|
322
335
|
|
323
336
|
it "should show the message with the custom values" do
|
324
|
-
@span.text.
|
337
|
+
expect(@span.text).to eq("Nain")
|
325
338
|
end
|
326
339
|
|
327
|
-
it "should render the proper data-collection" do
|
328
|
-
@span.attribute("data-collection").value.
|
340
|
+
it "should render the proper data-bip-collection" do
|
341
|
+
expect(@span.attribute("data-bip-collection").value).to eq(@collection.to_json)
|
329
342
|
end
|
330
343
|
end
|
331
344
|
|
@@ -333,39 +346,61 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
333
346
|
|
334
347
|
context "with a select attribute" do
|
335
348
|
before do
|
336
|
-
@countries = COUNTRIES
|
337
|
-
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :
|
349
|
+
@countries = COUNTRIES
|
350
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, as: :select, :collection => @countries)
|
338
351
|
@span = nk.css("span")
|
339
352
|
end
|
340
353
|
|
341
|
-
it
|
342
|
-
@span.attribute(
|
354
|
+
it 'should have a select data-bip-type' do
|
355
|
+
expect(@span.attribute('data-bip-type').value).to eq('select')
|
343
356
|
end
|
344
357
|
|
345
358
|
it "should have a proper data collection" do
|
346
|
-
@span.attribute(
|
359
|
+
expect(@span.attribute('data-bip-collection').value).to eq(@countries.to_json)
|
347
360
|
end
|
348
361
|
|
349
362
|
it "should show the current country" do
|
350
|
-
@span.text.
|
363
|
+
expect(@span.text).to eq("Italy")
|
351
364
|
end
|
352
365
|
|
353
|
-
it
|
354
|
-
@span.attribute(
|
366
|
+
it 'should include the proper data-bip-value' do
|
367
|
+
expect(@span.attribute('data-bip-value').value).to eq('2')
|
355
368
|
end
|
356
369
|
|
357
370
|
context "with an apostrophe in it" do
|
358
371
|
before do
|
359
|
-
@apostrophe_countries =
|
360
|
-
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :
|
372
|
+
@apostrophe_countries = {1=> "Joe's Country", 2 => "Bob's Country"}
|
373
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, as: :select, :collection => @apostrophe_countries)
|
361
374
|
@span = nk.css("span")
|
362
375
|
end
|
363
376
|
|
364
377
|
it "should have a proper data collection" do
|
365
|
-
@span.attribute(
|
378
|
+
expect(@span.attribute('data-bip-collection').value).to eq(@apostrophe_countries.to_json)
|
366
379
|
end
|
367
380
|
end
|
368
381
|
end
|
382
|
+
|
383
|
+
context 'custom container' do
|
384
|
+
before(:each) do
|
385
|
+
@old_container = BestInPlace.container
|
386
|
+
@user.save
|
387
|
+
BestInPlace.container = :p
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'should override container globally' do
|
391
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
|
392
|
+
expect(nk.css('p')).to_not be_empty
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'should use the container params' do
|
396
|
+
nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name, container: :div)
|
397
|
+
expect(nk.css('div')).to_not be_empty
|
398
|
+
end
|
399
|
+
|
400
|
+
after(:each) do
|
401
|
+
BestInPlace.container = @old_container
|
402
|
+
end
|
403
|
+
end
|
369
404
|
end
|
370
405
|
|
371
406
|
describe "#best_in_place_if" do
|
@@ -391,19 +426,19 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
391
426
|
it "should work with array-like objects in order to provide support to namespaces" do
|
392
427
|
nk = Nokogiri::HTML.parse(helper.best_in_place_if @condition, [:admin, @user], :name)
|
393
428
|
span = nk.css("span")
|
394
|
-
span.text.
|
429
|
+
expect(span.text).to eq("Lucia")
|
395
430
|
end
|
396
431
|
|
397
432
|
context "when the options parameter is left off" do
|
398
433
|
it "should call best_in_place with the rest of the parameters and empty options" do
|
399
|
-
helper.
|
434
|
+
expect(helper).to receive(:best_in_place).with(@user, :name, {})
|
400
435
|
helper.best_in_place_if @condition, @user, :name
|
401
436
|
end
|
402
437
|
end
|
403
438
|
|
404
439
|
context "when the options parameter is included" do
|
405
440
|
it "should call best_in_place with the rest of the parameters" do
|
406
|
-
helper.
|
441
|
+
expect(helper).to receive(:best_in_place).with(@user, :name, @options)
|
407
442
|
helper.best_in_place_if @condition, @user, :name, @options
|
408
443
|
end
|
409
444
|
end
|
@@ -413,15 +448,15 @@ describe BestInPlace::BestInPlaceHelpers do
|
|
413
448
|
before {@condition = false}
|
414
449
|
|
415
450
|
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).
|
451
|
+
expect(helper.best_in_place_if(@condition, [:admin, @user], :name)).to eq "Lucia"
|
417
452
|
end
|
418
453
|
|
419
454
|
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).
|
455
|
+
expect(helper.best_in_place_if(@condition, @user, :name)).to eq "Lucia"
|
421
456
|
end
|
422
457
|
|
423
458
|
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).
|
459
|
+
expect(helper.best_in_place_if(@condition, @user, :name, @options)).to eq "Lucia"
|
425
460
|
end
|
426
461
|
end
|
427
462
|
end
|