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.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -5
  3. data/.rspec +1 -0
  4. data/.travis.yml +12 -5
  5. data/Appraisals +17 -0
  6. data/CHANGELOG.md +51 -30
  7. data/Gemfile +15 -2
  8. data/README.md +52 -105
  9. data/best_in_place.gemspec +13 -11
  10. data/config.ru +7 -0
  11. data/gemfiles/rails_3.2.gemfile +24 -0
  12. data/gemfiles/rails_4.0.gemfile +23 -0
  13. data/gemfiles/rails_4.1.gemfile +23 -0
  14. data/gemfiles/rails_edge.gemfile +25 -0
  15. data/lib/assets/javascripts/best_in_place.jquery-ui.js +57 -0
  16. data/lib/assets/javascripts/best_in_place.js +551 -650
  17. data/lib/assets/javascripts/best_in_place.purr.js +16 -6
  18. data/lib/best_in_place.rb +29 -9
  19. data/lib/best_in_place/controller_extensions.rb +10 -13
  20. data/lib/best_in_place/display_methods.rb +26 -21
  21. data/lib/best_in_place/engine.rb +2 -2
  22. data/lib/best_in_place/helper.rb +145 -87
  23. data/lib/best_in_place/railtie.rb +5 -2
  24. data/lib/best_in_place/test_helpers.rb +0 -1
  25. data/lib/best_in_place/utils.rb +20 -12
  26. data/lib/best_in_place/version.rb +1 -1
  27. data/spec/{helpers/best_in_place_spec.rb → helper_spec.rb} +134 -99
  28. data/spec/integration/double_init_spec.rb +3 -5
  29. data/spec/integration/js_spec.rb +193 -123
  30. data/spec/integration/live_spec.rb +3 -4
  31. data/spec/integration/text_area_spec.rb +4 -4
  32. data/spec/internal/app/assets/images/info.png +0 -0
  33. data/{test_app → spec/internal}/app/assets/images/no.png +0 -0
  34. data/spec/internal/app/assets/images/purrBottom.png +0 -0
  35. data/spec/internal/app/assets/images/purrClose.png +0 -0
  36. data/spec/internal/app/assets/images/purrTop.png +0 -0
  37. data/{test_app → spec/internal}/app/assets/images/red_pen.png +0 -0
  38. data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  39. data/{test_app → spec/internal}/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  40. data/{test_app → spec/internal}/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
  41. data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  42. data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  43. data/{test_app → spec/internal}/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  44. data/{test_app → spec/internal}/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  45. data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  46. data/{test_app → spec/internal}/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  47. data/{test_app → spec/internal}/app/assets/images/ui-icons_222222_256x240.png +0 -0
  48. data/{test_app → spec/internal}/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
  49. data/{test_app → spec/internal}/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
  50. data/{test_app → spec/internal}/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
  51. data/{test_app → spec/internal}/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
  52. data/{test_app → spec/internal}/app/assets/images/yes.png +0 -0
  53. data/spec/internal/app/assets/javascripts/application.js +37 -0
  54. data/{test_app → spec/internal}/app/assets/stylesheets/.gitkeep +0 -0
  55. data/{test_app → spec/internal}/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb +1 -2
  56. data/{test_app → spec/internal}/app/assets/stylesheets/scaffold.css +1 -1
  57. data/{test_app → spec/internal}/app/assets/stylesheets/style.css.erb +2 -4
  58. data/{test_app → spec/internal}/app/controllers/admin/users_controller.rb +8 -3
  59. data/{test_app → spec/internal}/app/controllers/application_controller.rb +0 -0
  60. data/{test_app → spec/internal}/app/controllers/cuca/cars_controller.rb +0 -0
  61. data/{test_app → spec/internal}/app/controllers/users_controller.rb +8 -40
  62. data/{test_app → spec/internal}/app/helpers/application_helper.rb +0 -0
  63. data/spec/internal/app/helpers/users_helper.rb +29 -0
  64. data/{test_app → spec/internal}/app/models/cuca/car.rb +0 -0
  65. data/{test_app → spec/internal}/app/models/user.rb +5 -1
  66. data/{test_app → spec/internal}/app/views/admin/users/show.html.erb +2 -2
  67. data/{test_app → spec/internal}/app/views/cuca/cars/show.html.erb +0 -0
  68. data/{test_app → spec/internal}/app/views/layouts/application.html.erb +1 -1
  69. data/{test_app → spec/internal}/app/views/users/_form.html.erb +2 -2
  70. data/{test_app → spec/internal}/app/views/users/double_init.html.erb +4 -10
  71. data/spec/internal/app/views/users/edit.html.erb +5 -0
  72. data/{test_app → spec/internal}/app/views/users/email_field.html.erb +0 -0
  73. data/{test_app → spec/internal}/app/views/users/index.html.erb +0 -0
  74. data/{test_app → spec/internal}/app/views/users/new.html.erb +0 -0
  75. data/{test_app → spec/internal}/app/views/users/show.html.erb +32 -24
  76. data/{test_app → spec/internal}/app/views/users/show_ajax.html.erb +0 -0
  77. data/spec/internal/config/database.yml +5 -0
  78. data/{test_app → spec/internal}/config/initializers/countries.rb +0 -0
  79. data/{test_app → spec/internal}/config/initializers/default_date_format.rb +0 -0
  80. data/spec/internal/config/initializers/development.rb +8 -0
  81. data/{test_app → spec/internal}/config/routes.rb +1 -2
  82. data/spec/internal/db/schema.rb +26 -0
  83. data/{test_app → spec/internal}/public/favicon.ico +0 -0
  84. data/spec/rails_helper.rb +21 -0
  85. data/spec/support/retry_on_timeout.rb +4 -7
  86. data/spec/utils_spec.rb +21 -0
  87. data/vendor/assets/javascripts/jquery.autosize.js +272 -0
  88. data/{lib → vendor}/assets/javascripts/jquery.purr.js +1 -1
  89. metadata +92 -175
  90. data/lib/best_in_place/check_version.rb +0 -8
  91. data/spec/spec_helper.rb +0 -23
  92. data/test_app/Gemfile +0 -16
  93. data/test_app/README +0 -256
  94. data/test_app/Rakefile +0 -7
  95. data/test_app/app/assets/javascripts/application.js +0 -35
  96. data/test_app/app/helpers/users_helper.rb +0 -29
  97. data/test_app/config.ru +0 -4
  98. data/test_app/config/application.rb +0 -51
  99. data/test_app/config/boot.rb +0 -13
  100. data/test_app/config/database.yml +0 -22
  101. data/test_app/config/environment.rb +0 -5
  102. data/test_app/config/environments/development.rb +0 -25
  103. data/test_app/config/environments/production.rb +0 -49
  104. data/test_app/config/environments/test.rb +0 -35
  105. data/test_app/config/initializers/backtrace_silencers.rb +0 -7
  106. data/test_app/config/initializers/inflections.rb +0 -10
  107. data/test_app/config/initializers/mime_types.rb +0 -5
  108. data/test_app/config/initializers/secret_token.rb +0 -7
  109. data/test_app/config/initializers/session_store.rb +0 -8
  110. data/test_app/config/locales/en.yml +0 -5
  111. data/test_app/db/migrate/20101206205922_create_users.rb +0 -18
  112. data/test_app/db/migrate/20101212170114_add_receive_email_to_user.rb +0 -9
  113. data/test_app/db/migrate/20110115204441_add_description_to_user.rb +0 -9
  114. data/test_app/db/migrate/20111210084202_add_favorite_color_to_users.rb +0 -5
  115. data/test_app/db/migrate/20111210084251_add_favorite_books_to_users.rb +0 -5
  116. data/test_app/db/migrate/20111217215935_add_birth_date_to_users.rb +0 -5
  117. data/test_app/db/migrate/20111224181356_add_money_to_user.rb +0 -5
  118. data/test_app/db/migrate/20120513003308_create_cars.rb +0 -11
  119. data/test_app/db/migrate/20120607172609_add_favorite_movie_to_users.rb +0 -5
  120. data/test_app/db/migrate/20120616170454_add_money_proc_to_users.rb +0 -6
  121. data/test_app/db/migrate/20120620165212_add_height_to_user.rb +0 -5
  122. data/test_app/db/migrate/20130213224102_add_favorite_locale_to_users.rb +0 -5
  123. data/test_app/db/schema.rb +0 -41
  124. data/test_app/db/seeds.rb +0 -19
  125. data/test_app/doc/README_FOR_APP +0 -2
  126. data/test_app/lib/tasks/.gitkeep +0 -0
  127. data/test_app/lib/tasks/cron.rake +0 -7
  128. data/test_app/public/404.html +0 -26
  129. data/test_app/public/422.html +0 -26
  130. data/test_app/public/500.html +0 -26
  131. data/test_app/public/robots.txt +0 -5
  132. data/test_app/script/rails +0 -6
  133. data/test_app/test/fixtures/users.yml +0 -17
  134. data/test_app/test/functional/users_controller_test.rb +0 -49
  135. data/test_app/test/performance/browsing_test.rb +0 -9
  136. data/test_app/test/test_helper.rb +0 -13
  137. data/test_app/test/unit/helpers/users_helper_test.rb +0 -4
  138. data/test_app/test/unit/user_test.rb +0 -8
  139. 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
- initializer "set view helpers" do
5
+ class Railtie < ::Rails::Railtie #:nodoc:
6
+ config.after_initialize do
4
7
  BestInPlace::ViewHelpers = ActionView::Base.new
5
8
  end
6
9
  end
@@ -1,6 +1,5 @@
1
1
  module BestInPlace
2
2
  module TestHelpers
3
-
4
3
  include ActionView::Helpers::JavaScriptHelper
5
4
 
6
5
  def bip_area(model, attr, new_value)
@@ -1,21 +1,29 @@
1
1
  module BestInPlace
2
- module Utils
3
- extend self
4
-
2
+ module Utils #:nodoc:
3
+ module_function
5
4
  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}"
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
- return object.class.to_s.underscore unless object.class.respond_to?(:model_name)
18
- ActiveModel::Naming.param_key(object.class)
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,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = "2.1.0"
2
+ VERSION = '3.0.0.rc1'
3
3
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
- require "spec_helper"
3
2
 
4
- describe BestInPlace::BestInPlaceHelpers do
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, :path => helper.cuca_cars_path)
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.should == "best_in_place_cuca_car_#{@car.id}_model"
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.should_not be_empty
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
- lambda { helper.best_in_place(@user, :money, :display_with => :number_to_currency, :display_as => :custom) }.should raise_error(ArgumentError)
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.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"
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.should == "best_in_place"
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.should == "name"
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.should == "user"
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").should be_nil
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").should be_nil
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").should be_nil
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").should be_nil
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").should be_nil
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-use-confirm").should be_nil
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").should be_nil
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.should == "/users/#{@user.id}"
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, :path => "/custom/path"
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.should == "/custom/path"
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, :path => helper.users_path
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.should == "/users"
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, :path => {:controller => :users, :action => :edit, :id => 23}
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.should == "/users/23/edit"
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-nil").should be_nil
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.stub!(:name).and_return(nil)
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.should == ""
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.stub!(:name).and_return("")
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.should == ""
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.should == "awesome"
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.should == "awesome"
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.should == "okay"
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.should == "okay-class"
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.should == "nasty"
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.should == "nasty-class"
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 have the given Use-Confirmation dialog option" do
191
- out = helper.best_in_place @user, :name, :use_confirm => "false"
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("data-use-confirm").value.should == "false"
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, :object_name => "my_user"
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.should == "my_user"
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.should == "awesome"
211
- span.attribute("data-bar").value.should == "nasty"
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.should_receive(:address_format).and_return("the result")
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.should == "the result"
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.should == "$150.00"
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.should == "LUCIA"
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
- lambda { helper.best_in_place @user, :money, :display_with => :fk_number_to_currency }.should raise_error(ArgumentError)
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.should == "º150.00"
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.should == "Lucia"
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.should == "Lucia"
280
+ expect(@span.text).to eq("Lucia")
268
281
  end
269
282
 
270
- it "should have an input data-type" do
271
- @span.attribute("data-type").value.should == "input"
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 "should have no data-collection" do
275
- @span.attribute("data-collection").should be_nil
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, :type => :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.should == @user.birth_date.to_date.to_s
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.should == "date"
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").should be_nil
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, :type => :checkbox)
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.should == "checkbox"
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 = ["No", "Yes"]
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.should == "No"
326
+ expect(@span.text).to eq("No")
315
327
  end
316
328
 
317
329
  describe "custom collection" do
318
330
  before do
319
- nk = Nokogiri::HTML.parse(helper.best_in_place @user, :receive_email, :type => :checkbox, :collection => ["Nain", "Da"])
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.should == "Nain"
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.should == ["Nain", "Da"].to_json
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.to_a
337
- nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @countries)
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 "should have a select data-type" do
342
- @span.attribute("data-type").value.should == "select"
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("data-collection").value.should == @countries.to_json
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.should == "Italy"
363
+ expect(@span.text).to eq("Italy")
351
364
  end
352
365
 
353
- it "should include the proper data-value" do
354
- @span.attribute("data-value").value.should == "2"
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 = [[1, "Joe's Country"], [2, "Bob's Country"]]
360
- nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, :type => :select, :collection => @apostrophe_countries)
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("data-collection").value.should == @apostrophe_countries.to_json
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.should == "Lucia"
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.should_receive(:best_in_place).with(@user, :name, {})
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.should_receive(:best_in_place).with(@user, :name, @options)
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).should eq "Lucia"
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).should eq "Lucia"
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).should eq "Lucia"
459
+ expect(helper.best_in_place_if(@condition, @user, :name, @options)).to eq "Lucia"
425
460
  end
426
461
  end
427
462
  end