best_in_place 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7128e2317c366f2b4b3c07523f9a7007c9d441f
4
- data.tar.gz: cd010b383a647c68f71c91ec0bc6351da8777be3
3
+ metadata.gz: e5e84415483a33f06ae8ad58a61c1659b185568e
4
+ data.tar.gz: eb2b9be33ed3f859f29222028b4143ec05b8c582
5
5
  SHA512:
6
- metadata.gz: acb6ef8c4bf474ac43408fb12c0c37cee42c4fbb4dde9419ab3abb415ba32f29d45de261129036712fc46fcd09d48b0957a7986c90ea5e80e5edfcc273c85521
7
- data.tar.gz: f64607487b57f5531b5d789df4cc168d07344e0282c0660492f16e477344d3a3efe191c6083ba17060c855973ecdfca492363a0fd4d71e0ea6322579781dfbe2
6
+ metadata.gz: 5403e603dd30cd6d28be3e39ba6bec7a2c407918a7b8759da50712fcdce2fd9af5b59e69eacde956d21086c6ccbbee7980aa1fe2d1d0dbeaeb2c1f8c68269e92
7
+ data.tar.gz: ea7dc137ed0816109d9debb3b7782349d6fcf7a587c66725eab2e6ddc3a5ac1006dba2170e2c8ca7a6e8a58b990c86dcb530d104d6f85c79b043f8f2b818971f
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ spec/internal/tmp/**/*
11
11
 
12
12
  .rvmrc
13
13
  coverage
14
+ tmp
@@ -1,7 +1,10 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
5
+ - 2.1
3
6
  - 1.9.3
4
- - 2.1.2
7
+ - 2.2
5
8
  - rbx-2
6
9
 
7
10
  env: "RAILS_ENV=test DISPLAY=:99.0"
@@ -9,6 +12,7 @@ gemfile:
9
12
  - gemfiles/rails_3.2.gemfile
10
13
  - gemfiles/rails_4.0.gemfile
11
14
  - gemfiles/rails_4.1.gemfile
15
+ - gemfiles/rails_4.2.gemfile
12
16
  - gemfiles/rails_edge.gemfile
13
17
 
14
18
  matrix:
data/Appraisals CHANGED
@@ -1,14 +1,18 @@
1
1
  appraise "rails-3.2" do
2
- gem 'rails', '3.2.19'
2
+ gem 'rails', github: "rails/rails", branch: '3-2-stable'
3
3
  gem 'strong_parameters'
4
4
  end
5
5
 
6
6
  appraise "rails-4.0" do
7
- gem "rails", "~> 4.0.0"
7
+ gem "rails", github: "rails/rails", branch: '4-0-stable'
8
8
  end
9
9
 
10
10
  appraise "rails-4.1" do
11
- gem "rails", "~> 4.1.0"
11
+ gem "rails", github: "rails/rails", branch: '4-1-stable'
12
+ end
13
+
14
+ appraise "rails-4.2" do
15
+ gem "rails", github: "rails/rails", branch: '4-2-stable'
12
16
  end
13
17
 
14
18
  appraise "rails-edge" do
data/README.md CHANGED
@@ -77,8 +77,7 @@ Params:
77
77
  Options:
78
78
 
79
79
  - **:type** It can be only [:input, :textarea, :select, :checkbox, :date (>= 1.0.4)] or if undefined it defaults to :input.
80
- - **:collection**: If you are using the :select type then you must specify the collection of values it takes as a hash where keys represent the display text and values are the option's value when selected. If you are
81
- using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No.
80
+ - **:collection**: If you are using the :select type then you must specify the collection of values it takes as a hash where values represent the display text and keys are the option's value when selected. If you are using the :checkbox type you can specify the two values it can take, or otherwise they will default to Yes and No.
82
81
  - **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path.
83
82
  - **:place_holder**: The nil param defines the content displayed in case no value is defined for that field. It can be something like "click me to edit".
84
83
  If not defined it will show *"-"*.
@@ -88,18 +87,30 @@ Options:
88
87
  - **:cancel_button**: (Inputs and textareas only) If set to a string, then a Cancel button will be shown with the string as its label.
89
88
  - **:cancel_button_class**: (Inputs and textareas only) Specifies any extra classes to set on the Cancel button.
90
89
  - **:sanitize**: True by default. If set to false the input/textarea will accept html tags.
91
- - **:html_attrs**: Hash of html arguments, such as maxlength, default-value etc.
90
+ - **:html_attrs**: Hash of html arguments such as maxlength, default-value, etc. that will be set on the rendered input **not** the best_in_place span.
92
91
  - **:inner_class**: Class that is set to the rendered input.
93
- - **:display_as**: A model method which will be called in order to display
94
- this field.
92
+ - **:display_as**: A **model** method which will be called in order to display this field. Cannot be used when using `display_with`.
93
+ - **:display_with**: A **helper** method or proc will be called in order to display this field. Cannot be used with `display_as`.
94
+ - **:helper_options**: A hash of parameters to be sent to the helper method specified by `display_with`.
95
95
  - **:as**: Used for overriding the default params key used for the object (the data-object attribute). Useful for e.g. STI scenarios where best_in_place should post to a common controller for different models.
96
96
  - **:data**: Hash of custom data attributes to be added to span. Can be used to provide data to the ajax:success callback.
97
97
  - **:class**: Additional classes to apply to the best_in_place span. Accepts either a string or Array of strings
98
98
  - **:value**: Customize the starting value of the inline input (defaults to to the field's value)
99
+ - **:id**: The HTML id of the best_in_place span. If not specified one is automatically generated.
100
+ - **:param**: If you wish to specific the object explicitly use this option.
101
+ - **:confirm**: If set to true displays a confirmation message when abandoning changes (pressing the escape key);
102
+
103
+ HTML Options:
104
+
105
+ If you provide an option that is not explicitly a best_in_place option it will be passed through when creating the best_in_place span.
106
+
107
+ So, for instance, if you want to add an HTML tab index to the best_in_place span just add it to your method call:
108
+
109
+ <%= best_in_place @user, :name, tabindex: "1" %>
99
110
 
100
111
  ###best_in_place_if
101
112
  **best_in_place_if condition, object, field, OPTIONS**
102
- see also **best_in_place_unless
113
+ see also **best_in_place_unless**
103
114
 
104
115
  It allows us to use best_in_place only if the first new parameter, a
105
116
  condition, is satisfied. Specifically:
@@ -123,7 +134,7 @@ It is a very useful feature to use with, for example, [Ryan Bates](https://githu
123
134
 
124
135
  ---
125
136
 
126
- ##Examples
137
+ ## Examples
127
138
 
128
139
  Examples (code in the views):
129
140
 
@@ -142,9 +153,12 @@ Examples (code in the views):
142
153
  ### Select
143
154
 
144
155
  <%= best_in_place @user, :country, :type => :select, :collection => {"1" => "Spain", "2" => "Italy", "3" => "Germany", "4" => "France"} %>
156
+ <%= best_in_place @user, :country, :type => :select, :collection => { es: 'Spain', it: 'Italy', de: 'Germany', fr: 'France' } %>
157
+ <%= best_in_place @user, :country, :type => :select, :collection => %w(Spain Italy Germany France) %>
158
+ <%= best_in_place @user, :country, :type => :select, :collection => [[1, 'Spain'], [3, 'Germany'], [2, 'Italy'], [4, 'France']] %>
145
159
 
146
160
  Of course it can take an instance or global variable for the collection, just remember the structure is a hash.
147
- The key will always be converted to a string for display. *
161
+ The value will always be converted to a string for display.
148
162
 
149
163
  ### Checkbox
150
164
 
@@ -269,7 +283,7 @@ In the view, we'd do:
269
283
  th= flavour
270
284
  - sizes.each do |size|
271
285
  tr
272
- %th= size
286
+ th= size
273
287
  - flavours.each do |flavour|
274
288
  - v = @ice_cream.get_stock(flavour: flavour, size: size)
275
289
  td= best_in_place v, :to_i, type: :input, url: set_stock_ice_cream_path(flavour: flavour, size: size)
@@ -353,8 +367,11 @@ Fork the project on [github](https://github.com/bernat/best_in_place 'bernat / b
353
367
 
354
368
  ### Run the specs
355
369
 
370
+ $ appraisal
356
371
  $ appraisal rspec
357
372
 
373
+ You many need to install appraisal: `gem install appraisal`
374
+
358
375
  ---
359
376
 
360
377
  ##Test Helpers
data/config.ru CHANGED
@@ -3,5 +3,28 @@ require 'bundler'
3
3
 
4
4
  Bundler.require :default, :development
5
5
 
6
- Combustion.initialize! :active_record
6
+ Combustion.initialize! :active_record do
7
+ if ENV['RACK_ENV'] == 'development'
8
+ config.assets.debug = true
9
+ end
10
+ end
11
+
12
+ if ENV['RACK_ENV'] == 'development'
13
+ User.create! :name => "Lucia",
14
+ :last_name => "Napoli",
15
+ :email => "lucianapoli@gmail.com",
16
+ :height => "h51",
17
+ :address => "Via Roma 99",
18
+ :zip => "25123",
19
+ :country => "2",
20
+ :receive_email => false,
21
+ :birth_date => Time.now.utc,
22
+ :money => 100,
23
+ :money_proc => 100,
24
+ :favorite_color => 'Red',
25
+ :favorite_books => "The City of Gold and Lead",
26
+ :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.",
27
+ :favorite_movie => "The Hitchhiker's Guide to the Galaxy"
28
+ end
7
29
  run Combustion::Application
30
+
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
  source "https://rails-assets.org"
5
5
 
6
+ gem "activerecord"
6
7
  gem "rails-assets-jquery", "1.11.1"
7
8
  gem "rails-assets-jquery-ui", "1.10.4"
8
9
  gem "rdiscount"
@@ -15,7 +16,7 @@ gem "poltergeist"
15
16
  gem "sqlite3"
16
17
  gem "appraisal"
17
18
  gem "launchy"
18
- gem "rails", "3.2.19"
19
+ gem "rails", :github => "rails/rails", :branch => "3-2-stable"
19
20
  gem "strong_parameters"
20
21
 
21
22
  platforms :mri_21 do
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
  source "https://rails-assets.org"
5
5
 
6
+ gem "activerecord"
6
7
  gem "rails-assets-jquery", "1.11.1"
7
8
  gem "rails-assets-jquery-ui", "1.10.4"
8
9
  gem "rdiscount"
@@ -15,7 +16,7 @@ gem "poltergeist"
15
16
  gem "sqlite3"
16
17
  gem "appraisal"
17
18
  gem "launchy"
18
- gem "rails", "~> 4.0.0"
19
+ gem "rails", :github => "rails/rails", :branch => "4-0-stable"
19
20
 
20
21
  platforms :mri_21 do
21
22
  gem "byebug"
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
  source "https://rails-assets.org"
5
5
 
6
+ gem "activerecord"
6
7
  gem "rails-assets-jquery", "1.11.1"
7
8
  gem "rails-assets-jquery-ui", "1.10.4"
8
9
  gem "rdiscount"
@@ -15,7 +16,7 @@ gem "poltergeist"
15
16
  gem "sqlite3"
16
17
  gem "appraisal"
17
18
  gem "launchy"
18
- gem "rails", "~> 4.1.0"
19
+ gem "rails", :github => "rails/rails", :branch => "4-1-stable"
19
20
 
20
21
  platforms :mri_21 do
21
22
  gem "byebug"
@@ -0,0 +1,25 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+ source "https://rails-assets.org"
5
+
6
+ gem "activerecord"
7
+ gem "rails-assets-jquery", "1.11.1"
8
+ gem "rails-assets-jquery-ui", "1.10.4"
9
+ gem "rdiscount"
10
+ gem "rspec-rails"
11
+ gem "nokogiri"
12
+ gem "combustion"
13
+ gem "sprockets-rails"
14
+ gem "capybara"
15
+ gem "poltergeist"
16
+ gem "sqlite3"
17
+ gem "appraisal"
18
+ gem "launchy"
19
+ gem "rails", :github => "rails/rails", :branch => "4-2-stable"
20
+
21
+ platforms :mri_21 do
22
+ gem "byebug"
23
+ end
24
+
25
+ gemspec :path => "../"
@@ -3,6 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
  source "https://rails-assets.org"
5
5
 
6
+ gem "activerecord"
6
7
  gem "rails-assets-jquery", "1.11.1"
7
8
  gem "rails-assets-jquery-ui", "1.10.4"
8
9
  gem "rdiscount"
@@ -18,6 +18,7 @@ BestInPlaceEditor.forms.date = {
18
18
  .attr('type', 'text')
19
19
  .attr('name', this.attributeName)
20
20
  .attr('value', this.sanitizeValue(this.display_value));
21
+
21
22
  if (this.inner_class !== null) {
22
23
  input_elt.addClass(this.inner_class);
23
24
  }
@@ -120,12 +120,11 @@ BestInPlaceEditor.prototype = {
120
120
  this.previousCollectionValue = value;
121
121
 
122
122
  // search for the text for the span
123
- jQuery.each(this.values, function (i, v) {
124
- if (String(value) === String(i)) {
125
- editor.element.html(v);
126
- }
127
- }
128
- );
123
+ var key, val, _i, _len, _ref, a;
124
+ for (_i = 0, a = this.values, _len = a.length; _i < _len; _i++) {
125
+ _ref = a[_i], key = _ref[0], val = _ref[1];
126
+ if (String(value) === String(key)) editor.element.html(val);
127
+ };
129
128
  break;
130
129
 
131
130
  case "checkbox":
@@ -191,17 +190,23 @@ BestInPlaceEditor.prototype = {
191
190
  self.okButtonClass = self.element.data("bipOkButtonClass") || self.okButtonClass || BestInPlaceEditor.defaults.okButtonClass;
192
191
  self.cancelButton = self.element.data("bipCancelButton") || self.cancelButton;
193
192
  self.cancelButtonClass = self.element.data("bipCancelButtonClass") || self.cancelButtonClass || BestInPlaceEditor.defaults.cancelButtonClass;
194
- self.placeHolder = self.element.data("bipPlaceholder") || BestInPlaceEditor.defaults.locales[''].placeHolder;
193
+
194
+ // Fix for default values of 0
195
+ if (self.element.data("bipPlaceholder") == null) {
196
+ self.placeHolder = BestInPlaceEditor.defaults.locales[''].placeHolder;
197
+ } else {
198
+ self.placeHolder = self.element.data("bipPlaceholder");
199
+ }
200
+
195
201
  self.inner_class = self.element.data("bipInnerClass");
196
202
  self.html_attrs = self.element.data("bipHtmlAttrs");
197
203
  self.original_content = self.element.data("bipOriginalContent") || self.original_content;
198
-
204
+
199
205
  // if set the input won't be satinized
200
206
  self.display_raw = self.element.data("bip-raw");
201
207
 
202
208
  self.useConfirm = self.element.data("bip-confirm");
203
209
 
204
-
205
210
  if (self.formType === "select" || self.formType === "checkbox") {
206
211
  self.values = self.collection;
207
212
  self.collectionValue = self.element.data("bipValue") || self.collectionValue;
@@ -453,17 +458,18 @@ BestInPlaceEditor.forms = {
453
458
  selected = '',
454
459
  select_elt = jQuery(document.createElement('select'))
455
460
  .attr('class', this.inner_class !== null ? this.inner_class : ''),
456
- currentCollectionValue = this.collectionValue;
457
-
458
- jQuery.each(this.values, function (key, value) {
461
+ currentCollectionValue = this.collectionValue,
462
+ a, key, value, _i, _len, _ref;
463
+ for (_i = 0, a = this.values, _len = a.length; _i < _len; _i++) {
464
+ _ref = a[_i], key = _ref[0], value = _ref[1];
459
465
  var option_elt = jQuery(document.createElement('option'))
460
466
  .val(key)
461
467
  .html(value);
462
- if (key === String(currentCollectionValue)) {
468
+ if (String(key) === String(currentCollectionValue)) {
463
469
  option_elt.attr('selected', 'selected');
464
- }
470
+ };
465
471
  select_elt.append(option_elt);
466
- });
472
+ };
467
473
  output.append(select_elt);
468
474
 
469
475
  this.element.html(output);
@@ -472,6 +478,17 @@ BestInPlaceEditor.forms = {
472
478
  this.element.find("select").bind('blur', {editor: this}, BestInPlaceEditor.forms.select.blurHandler);
473
479
  this.element.find("select").bind('keyup', {editor: this}, BestInPlaceEditor.forms.select.keyupHandler);
474
480
  this.element.find("select")[0].focus();
481
+
482
+ // automatically click on the select so you
483
+ // don't have to click twice
484
+ try {
485
+ var e = document.createEvent("MouseEvents");
486
+ e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
487
+ this.element.find("select")[0].dispatchEvent(e);
488
+ }
489
+ catch(e) {
490
+ // browser doesn't support this, e.g. IE8
491
+ }
475
492
  },
476
493
 
477
494
  getValue: function () {
@@ -1,6 +1,7 @@
1
1
  module BestInPlace
2
2
  module Helper
3
3
  def best_in_place(object, field, opts = {})
4
+
4
5
  best_in_place_assert_arguments(opts)
5
6
  type = opts[:as] || :input
6
7
  field = field.to_s
@@ -19,26 +20,21 @@ module BestInPlace
19
20
  if opts[:collection] or type == :checkbox
20
21
  collection = opts[:collection]
21
22
  value = value.to_s
22
- case type
23
- when :checkbox
24
- if collection.blank?
25
- collection = best_in_place_default_collection
26
- else
27
- collection = best_in_place_collection_builder(type, collection)
28
- end
29
- display_value = collection[value]
30
- collection = collection.to_json
31
- else # :select
32
- collection = best_in_place_collection_builder(type, collection)
33
- display_value = collection[value]
34
- collection = collection.to_json
23
+ collection = if collection.blank?
24
+ best_in_place_default_collection
25
+ else
26
+ best_in_place_collection_builder(type, collection)
35
27
  end
28
+ display_value = collection.flat_map{|a| a[0].to_s == value ? a[1] : nil }.compact[0]
29
+ collection = collection.to_json
36
30
  options[:data]['bip-collection'] = html_escape(collection)
37
31
  end
38
32
 
39
33
  options[:class] = ['best_in_place'] + Array(opts[:class] || opts[:classes])
40
34
  options[:id] = opts[:id] || BestInPlace::Utils.build_best_in_place_id(real_object, field)
41
35
 
36
+ pass_through_html_options(opts, options)
37
+
42
38
  options[:data]['bip-activator'] = opts[:activator].presence
43
39
 
44
40
  options[:data]['bip-html-attrs'] = opts[:html_attrs].to_json unless opts[:html_attrs].blank?
@@ -82,6 +78,16 @@ module BestInPlace
82
78
 
83
79
  private
84
80
 
81
+ def pass_through_html_options(opts, options)
82
+ known_keys = [:id, :type, :nil, :classes, :collection, :data,
83
+ :activator, :cancel_button, :cancel_button_class, :html_attrs, :inner_class, :nil,
84
+ :object_name, :ok_button, :ok_button_class, :display_as, :display_with, :path, :value,
85
+ :use_confirm, :confirm, :sanitize, :raw, :helper_options, :url, :place_holder, :class,
86
+ :as, :param, :container]
87
+ uknown_keys = opts.keys - known_keys
88
+ uknown_keys.each { |key| options[key] = opts[key] }
89
+ end
90
+
85
91
  def best_in_place_build_value_for(object, field, opts)
86
92
  klass = object.class
87
93
  if opts[:display_as]
@@ -102,8 +108,6 @@ module BestInPlace
102
108
  if field_value.blank?
103
109
  ''
104
110
  else
105
-
106
-
107
111
  BestInPlace::ViewHelpers.send(opts[:display_with], field_value)
108
112
  end
109
113
  end
@@ -118,12 +122,6 @@ module BestInPlace
118
122
  end
119
123
 
120
124
  def best_in_place_assert_arguments(args)
121
- args.assert_valid_keys(:id, :type, :nil, :classes, :collection, :data,
122
- :activator, :cancel_button, :cancel_button_class, :html_attrs, :inner_class, :nil,
123
- :object_name, :ok_button, :ok_button_class, :display_as, :display_with, :path, :value,
124
- :use_confirm, :confirm, :sanitize, :raw, :helper_options, :url, :place_holder, :class,
125
- :as, :param, :container)
126
-
127
125
  best_in_place_deprecated_options(args)
128
126
 
129
127
  if args[:display_as] && args[:display_with]
@@ -177,17 +175,26 @@ module BestInPlace
177
175
  when Array
178
176
  if type == :checkbox
179
177
  if collection.length == 2
180
- {'false' => collection[0], 'true' => collection[1]}
178
+ {'false' => collection[0], 'true' => collection[1]}.stringify_keys
181
179
  else
182
180
  fail ArgumentError, '[Best_in_place] :collection array should have 2 values'
183
181
  end
184
182
  else # :select
185
- Hash[(1...collection.size+1).zip collection]
183
+ case collection[0]
184
+ when Array
185
+ collection
186
+ else
187
+ if collection[0].length == 2
188
+ collection.to_a
189
+ else
190
+ collection.each_with_index.map{|a,i| [i+1,a]}
191
+ end
192
+ end
186
193
  end
187
194
  else
188
- collection
195
+ collection.to_a
189
196
  end
190
- collection.stringify_keys
197
+ collection
191
198
  end
192
199
 
193
200
  def best_in_place_default_collection
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  end
@@ -123,12 +123,12 @@ describe BestInPlace::Helper, type: :helper do
123
123
  end
124
124
  end
125
125
 
126
- describe "nil option" do
127
- it "should have no nil data by default" do
126
+ describe "placeholder option" do
127
+ it "should have no placeholder data by default" do
128
128
  expect(@span.attribute("data-bip-placeholder")).to be_nil
129
129
  end
130
130
 
131
- it "should show '' if the object responds with nil for the passed attribute" do
131
+ it "should show '' if the object responds with placeholder for the passed attribute" do
132
132
  expect(@user).to receive(:name).twice.and_return("")
133
133
  nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
134
134
  span = nk.css("span")
@@ -141,6 +141,7 @@ describe BestInPlace::Helper, type: :helper do
141
141
  span = nk.css("span")
142
142
  expect(span.text).to eq("")
143
143
  end
144
+
144
145
  end
145
146
 
146
147
  it "should have the given inner_class" do
@@ -338,7 +339,7 @@ describe BestInPlace::Helper, type: :helper do
338
339
  end
339
340
 
340
341
  it "should render the proper data-bip-collection" do
341
- expect(@span.attribute("data-bip-collection").value).to eq(@collection.to_json)
342
+ expect(@span.attribute("data-bip-collection").value).to eq(@collection.to_a.to_json)
342
343
  end
343
344
  end
344
345
 
@@ -370,6 +371,7 @@ describe BestInPlace::Helper, type: :helper do
370
371
  @countries_hash = COUNTRIES_HASH
371
372
  @countries_hash_string_keys = COUNTRIES_HASH_STRING_KEYS
372
373
  @countries_array = COUNTRIES_ARRAY
374
+ @countries_array_of_arrays = COUNTRIES_ARRAY_OF_ARRAYS
373
375
  @apostrophe_countries_hash = COUNTRIES_APOSTROPHE_HASH
374
376
  @apostrophe_countries_array = COUNTRIES_APOSTROPHE_ARRAY
375
377
  end
@@ -385,7 +387,7 @@ describe BestInPlace::Helper, type: :helper do
385
387
  end
386
388
 
387
389
  it 'should have a proper data collection' do
388
- expect(@span.attribute('data-bip-collection').value).to eq(@countries_hash.to_json)
390
+ expect(@span.attribute('data-bip-collection').value).to eq(@countries_hash.to_a.to_json)
389
391
  end
390
392
 
391
393
  it 'should show the current country' do
@@ -405,7 +407,7 @@ describe BestInPlace::Helper, type: :helper do
405
407
  end
406
408
 
407
409
  it 'should have a proper data collection' do
408
- expect(@span.attribute('data-bip-collection').value).to eq(@countries_hash_string_keys.to_json)
410
+ expect(@span.attribute('data-bip-collection').value).to eq(@countries_hash_string_keys.to_a.to_json)
409
411
  end
410
412
 
411
413
  it 'should show the current country' do
@@ -424,7 +426,7 @@ describe BestInPlace::Helper, type: :helper do
424
426
  end
425
427
 
426
428
  it 'should have a proper data collection' do
427
- expect(@span.attribute('data-bip-collection').value).to eq(@apostrophe_countries_hash.to_json)
429
+ expect(@span.attribute('data-bip-collection').value).to eq(@apostrophe_countries_hash.to_a.to_json)
428
430
  end
429
431
  end
430
432
  end
@@ -436,7 +438,7 @@ describe BestInPlace::Helper, type: :helper do
436
438
  end
437
439
 
438
440
  it 'should have a proper data collection' do
439
- expect(@span.attribute('data-bip-collection').value).to eq(@countries_hash.to_json)
441
+ expect(@span.attribute('data-bip-collection').value).to eq(@countries_array.each_with_index.map{|a,i| [i+1,a]}.to_json)
440
442
  end
441
443
 
442
444
  it 'should show the current country' do
@@ -454,10 +456,48 @@ describe BestInPlace::Helper, type: :helper do
454
456
  end
455
457
 
456
458
  it 'should have a proper data collection' do
457
- expect(@span.attribute('data-bip-collection').value).to eq(@apostrophe_countries_hash.to_json)
459
+ expect(@span.attribute('data-bip-collection').value).to eq(@apostrophe_countries_array.each_with_index.map{|a,i| [i+1,a]}.to_json)
458
460
  end
459
461
  end
460
462
  end
463
+
464
+ describe 'with an array parameter' do
465
+ before do
466
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :country, as: :select, collection: @countries_array_of_arrays)
467
+ @span = nk.css('span')
468
+ end
469
+
470
+ it 'should have a proper data collection' do
471
+ expect(@span.attribute('data-bip-collection').value).to eq(@countries_array_of_arrays.to_json)
472
+ end
473
+
474
+ it 'should show the current country' do
475
+ expect(@span.text).to eq('Italy')
476
+ end
477
+
478
+ it 'should include the proper data-bip-value' do
479
+ expect(@span.attribute('data-bip-value').value).to eq('2')
480
+ end
481
+
482
+ end
483
+
484
+ describe "with html parameters" do
485
+ before do
486
+ @attrs = {tabindex: 1, width: "300px", height: "24px"}
487
+ nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name, @attrs)
488
+ @span = nk.css("span")
489
+ end
490
+
491
+ it 'should pass through html attributes to the best_in_place span' do
492
+ expect(@attrs.select {|key, value| @span.attribute(key.to_s) }).to eq(@attrs)
493
+ end
494
+
495
+ it 'should have the proper values set' do
496
+ expect(@attrs.map {|key, value| @span.attribute(key.to_s).value }).to eq(@attrs.map {|key, value| value.to_s })
497
+ end
498
+
499
+ end
500
+
461
501
  end
462
502
 
463
503
  context 'custom container' do
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ describe "Placeholder behavior", :js => true do
4
+ before do
5
+ @user = User.new name: "Zero",
6
+ last_name: "My Hero",
7
+ address: "0 Nowhere lane",
8
+ email: "zero@zero.com",
9
+ height: "0",
10
+ zip: "00000",
11
+ description: ""
12
+ end
13
+
14
+ it "should set a place_holder value" do
15
+ @user.save!
16
+ visit user_path(@user)
17
+ expect(find('#favorite_locale')).to have_content("N/A")
18
+ end
19
+
20
+ it "should allow the use of 0 for a placeholder" do
21
+ @user.save!
22
+ visit user_path(@user)
23
+ expect(find('#zero_field')).to have_content("0")
24
+ end
25
+
26
+ end
@@ -102,7 +102,7 @@
102
102
  <tr>
103
103
  <td>Money</td>
104
104
  <td id="money">
105
- <%= best_in_place @user, :money, :display_with => :number_to_currency %>
105
+ <%= best_in_place @user, :money, :display_with => :number_to_currency%>
106
106
  </td>
107
107
  </tr>
108
108
  <tr>
@@ -131,6 +131,13 @@
131
131
  <%= best_in_place @user, :favorite_movie, opts %>
132
132
  </td>
133
133
  </tr>
134
+ <tr>
135
+ <td>Zero Field</td>
136
+ <td id="zero_field">
137
+ <%= best_in_place @user, :zero_field, place_holder: 0 %>
138
+ </td>
139
+ </tr>
140
+
134
141
  </table>
135
142
  <br/>
136
143
  <hr/>
@@ -1,5 +1,6 @@
1
1
  COUNTRIES_HASH = { 1 => 'Spain', 2 => 'Italy', 3 => 'Germany', 4 => 'France' }
2
2
  COUNTRIES_HASH_STRING_KEYS = { es: 'Spain', it: 'Italy', de: 'Germany', fr: 'France' }
3
3
  COUNTRIES_ARRAY = %w(Spain Italy Germany France)
4
+ COUNTRIES_ARRAY_OF_ARRAYS = [[1, 'Spain'], [3, 'Germany'], [2, 'Italy'], [4, 'France']]
4
5
  COUNTRIES_APOSTROPHE_HASH = {1 => "Joe's Country", 2 => "Bob's Country"}
5
6
  COUNTRIES_APOSTROPHE_ARRAY = ["Joe's Country", "Bob's Country"]
@@ -22,5 +22,6 @@ ActiveRecord::Schema.define do
22
22
  t.string "height"
23
23
  t.string "favorite_movie"
24
24
  t.string "favorite_locale"
25
+ t.integer "zero_field"
25
26
  end
26
27
  end
@@ -2,6 +2,6 @@ def retry_on_timeout(n = 3, &block)
2
2
  block.call
3
3
  rescue => e
4
4
  fail if n.zero?
5
- puts "Catched error: #{e.message}. #{n-1} more attempts."
5
+ puts "Caught error: #{e.message}. #{n-1} more attempts."
6
6
  retry_on_timeout(n - 1, &block)
7
- end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernat Farrero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -61,6 +61,7 @@ files:
61
61
  - gemfiles/rails_3.2.gemfile
62
62
  - gemfiles/rails_4.0.gemfile
63
63
  - gemfiles/rails_4.1.gemfile
64
+ - gemfiles/rails_4.2.gemfile
64
65
  - gemfiles/rails_edge.gemfile
65
66
  - lib/assets/javascripts/best_in_place.jquery-ui.js
66
67
  - lib/assets/javascripts/best_in_place.js
@@ -78,6 +79,7 @@ files:
78
79
  - spec/integration/double_init_spec.rb
79
80
  - spec/integration/js_spec.rb
80
81
  - spec/integration/live_spec.rb
82
+ - spec/integration/placeholder_spec.rb
81
83
  - spec/integration/text_area_spec.rb
82
84
  - spec/internal/app/assets/images/info.png
83
85
  - spec/internal/app/assets/images/no.png