best_in_place 3.1.0 → 3.1.1

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: 69cca3a71a33da7518f1fb792624d505c10e9018
4
- data.tar.gz: 9782236c6e4508607b856b0690ef29abaef84780
3
+ metadata.gz: f42b596132f7b09be9241f0d8b0c51af70ddfc08
4
+ data.tar.gz: de11ecdc29b0213492b844b18f20325eecdd931a
5
5
  SHA512:
6
- metadata.gz: 9d5d31fa17f831062346c9b21e9eac994cf948fe551d2c5699dc43c69ae508421374a4281cf58e3ef1860504a6e80736ff2cbf7665e05e3961359d2757a79d3c
7
- data.tar.gz: 5b4d5c558752d542e434060724909c356defa96932105e17d8b63d440562f1858a286714f131e68e97789d1f947b4b669b258bbbce65b6424ac2eb1e1704edf2
6
+ metadata.gz: 39a699e70e97bd086678ff33d4831116258de870b3666292de2b1dd3d95a672f4239fcac73521a525faa5d1ae897b6174efee1ea7c990cac6c0d794d52de8d34
7
+ data.tar.gz: 76e249d89a3376deb3d6a8ad4caeb9c387016ea28fa89d933459c741725ce1b5ecf6f4aebf22fce915a71809bca5e652736da633cc4bf53f52d8af97b1c7da4b
@@ -2,10 +2,9 @@ language: ruby
2
2
  sudo: false
3
3
  cache: bundler
4
4
  rvm:
5
- - 2.1
6
- - 1.9.3
7
- - 2.2
8
- - rbx-2
5
+ - 2.4.1
6
+ - 2.3.3
7
+ - 2.2.7
9
8
 
10
9
  env: "RAILS_ENV=test DISPLAY=:99.0"
11
10
  gemfile:
@@ -13,9 +12,23 @@ gemfile:
13
12
  - gemfiles/rails_4.0.gemfile
14
13
  - gemfiles/rails_4.1.gemfile
15
14
  - gemfiles/rails_4.2.gemfile
15
+ - gemfiles/rails_5.0.gemfile
16
+ - gemfiles/rails_5.1.gemfile
16
17
  - gemfiles/rails_edge.gemfile
17
18
 
18
19
  matrix:
19
20
  allow_failures:
20
21
  - gemfile: gemfiles/rails_edge.gemfile
21
- - rvm: rbx-2
22
+ exclude:
23
+ - rvm: 2.4.1
24
+ gemfile: gemfiles/rails_3.2.gemfile
25
+ - rvm: 2.4.1
26
+ gemfile: gemfiles/rails_4.0.gemfile
27
+ - rvm: 2.4.1
28
+ gemfile: gemfiles/rails_4.1.gemfile
29
+
30
+ before_install:
31
+ - mkdir travis-phantomjs
32
+ - wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
33
+ - tar -xvf $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis-phantomjs
34
+ - export PATH=$PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH
data/Appraisals CHANGED
@@ -17,6 +17,14 @@ appraise "rails-4.2" do
17
17
  gem "rails", github: "rails/rails", branch: '4-2-stable'
18
18
  end
19
19
 
20
+ appraise "rails-5.0" do
21
+ gem "rails", github: "rails/rails", branch: '5-0-stable'
22
+ end
23
+
24
+ appraise "rails-5.1" do
25
+ gem "rails", github: "rails/rails", branch: '5-1-stable'
26
+ end
27
+
20
28
  appraise "rails-edge" do
21
29
  gem "rails", github: "rails/rails"
22
30
  gem 'arel', github: 'rails/arel'
@@ -1,5 +1,14 @@
1
1
  #Changelog
2
2
  - unreleased
3
+
4
+ - v.3.1.1
5
+ - Chore/improve readme
6
+ - Upgrade PhantomJS version for travis and remove deprecation warning
7
+ - Add Tests in Rails 5+
8
+ - Bump ruby version support
9
+ - Fix markdown rendering of headings
10
+ - Fix README markdown preview
11
+ - Add a best_in_place:before-update event
3
12
  - add option[:skip_blur] to play nice with wysiwhtml5
4
13
 
5
14
  - v.3.0.3 :
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  **The Unobtrusive in Place editing solution**
4
4
 
5
5
 
6
- ##Description
6
+ ## Description
7
7
 
8
8
  **Best in Place** is a jQuery based AJAX Inplace-Editor that takes profit of RESTful server-side controllers to allow users to edit stuff with
9
9
  no need of forms. If the server has standard defined REST methods, particularly those to UPDATE your objects (HTTP PUT), then by adding the
@@ -13,9 +13,9 @@ The editor works by PUTting the updated value to the server and GETting the upda
13
13
 
14
14
  ---
15
15
 
16
- ##Installation
16
+ ## Installation
17
17
 
18
- ###Rails
18
+ ### Rails
19
19
 
20
20
  Installing *best_in_place* is very easy and straight-forward.
21
21
  Just begin including the gem in your Gemfile:
@@ -44,7 +44,7 @@ Then, just add a binding to prepare all best in place fields when the document i
44
44
 
45
45
  You are done!
46
46
 
47
- ##Features
47
+ ## Features
48
48
 
49
49
  - Compatible with text **inputs**
50
50
  - Compatible with **textarea**
@@ -62,9 +62,9 @@ You are done!
62
62
  - Custom display methods using a method from your model or an existing rails
63
63
  view helper
64
64
 
65
- ##Usage of Rails 3 Gem
65
+ ## Usage of Rails 3 Gem
66
66
 
67
- ###best_in_place
67
+ ### best_in_place
68
68
  **best_in_place object, field, OPTIONS**
69
69
 
70
70
  Params:
@@ -106,7 +106,7 @@ So, for instance, if you want to add an HTML tab index to the best_in_place span
106
106
 
107
107
  <%= best_in_place @user, :name, tabindex: "1" %>
108
108
 
109
- ###best_in_place_if
109
+ ### best_in_place_if
110
110
  **best_in_place_if condition, object, field, OPTIONS**
111
111
  see also **best_in_place_unless**
112
112
 
@@ -166,7 +166,7 @@ The value will always be converted to a string for display.
166
166
  If you use array as a collection, the first value is always the negative boolean value and the second the positive. Structure: `["false value", "true value"]`.
167
167
  If not defined, it will default to *Yes* and *No* options.
168
168
  Default true and false values are stored in locales
169
-
169
+
170
170
  t(:'best_in_place.yes', default: 'Yes')
171
171
  t(:'best_in_place.no', default: 'No')
172
172
 
@@ -260,7 +260,7 @@ And in your javascript:
260
260
 
261
261
  $('.best_in_place').bind("ajax:success", function(){ alert('Name updated for '+$(this).data('userName')); });
262
262
 
263
- ##Non Active Record environments
263
+ ## Non Active Record environments
264
264
  We are not planning to support other ORMs apart from Active Record, at least for now. So, you can perfectly consider the following workaround as *the right way* until a specific implementation is done for your ORM.
265
265
 
266
266
  Best In Place automatically assumes that Active Record is the ORM you are using. However, this might not be your case, as you might use another ORM (or not ORM at all for that case!). Good news for you: even in such situation Best In Place can be used!
@@ -340,7 +340,7 @@ You can configure some global options for best_in_place. Currently these options
340
340
  config.container = :div
341
341
  config.skip_blur = true
342
342
  end
343
-
343
+
344
344
 
345
345
  ## Notification
346
346
 
@@ -362,7 +362,7 @@ If the script is used with the Rails Gem no html tags will be allowed unless the
362
362
 
363
363
  ---
364
364
 
365
- ##TODO
365
+ ## TODO
366
366
 
367
367
  - Client Side Validation definitions
368
368
  - Accepting more than one handler to activate best_in_place fields
@@ -386,7 +386,7 @@ You many need to install appraisal: `gem install appraisal`
386
386
 
387
387
  ---
388
388
 
389
- ##Test Helpers
389
+ ## Test Helpers
390
390
  Best In Place has also some helpers that may be very useful for integration testing. Since it might very common to test some views using Best In Place, some helpers are provided to ease it.
391
391
 
392
392
  As of now, a total of four helpers are available. There is one for each of the following BIP types: a plain text input, a textarea, a boolean input and a selector. Its function is to simulate the user's action of filling such fields.
@@ -407,7 +407,7 @@ The parameters are defined here (some are method-specific):
407
407
 
408
408
  ---
409
409
 
410
- ##Authors, License and Stuff
410
+ ## Authors, License and Stuff
411
411
 
412
412
  Code by [Bernat Farrero](http://bernatfarrero.com) from [Itnig Web Services](http://itnig.net) (it was based on the [original project](http://github.com/janv/rest_in_place/) of Jan Varwig) and released under [MIT license](http://www.opensource.org/licenses/mit-license.php).
413
413
 
@@ -16,7 +16,7 @@ gem "poltergeist"
16
16
  gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
- gem "rails", :github => "rails/rails", :branch => "3-2-stable"
19
+ gem "rails", github: "rails/rails", branch: "3-2-stable"
20
20
  gem "strong_parameters"
21
21
  gem "test-unit"
22
22
 
@@ -24,4 +24,4 @@ platforms :mri_21 do
24
24
  gem "byebug"
25
25
  end
26
26
 
27
- gemspec :path => "../"
27
+ gemspec path: "../"
@@ -16,11 +16,11 @@ gem "poltergeist"
16
16
  gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
- gem "rails", :github => "rails/rails", :branch => "4-0-stable"
19
+ gem "rails", github: "rails/rails", branch: "4-0-stable"
20
20
  gem "test-unit"
21
21
 
22
22
  platforms :mri_21 do
23
23
  gem "byebug"
24
24
  end
25
25
 
26
- gemspec :path => "../"
26
+ gemspec path: "../"
@@ -16,10 +16,10 @@ gem "poltergeist"
16
16
  gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
- gem "rails", :github => "rails/rails", :branch => "4-1-stable"
19
+ gem "rails", github: "rails/rails", branch: "4-1-stable"
20
20
 
21
21
  platforms :mri_21 do
22
22
  gem "byebug"
23
23
  end
24
24
 
25
- gemspec :path => "../"
25
+ gemspec path: "../"
@@ -16,10 +16,10 @@ gem "poltergeist"
16
16
  gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
- gem "rails", :github => "rails/rails", :branch => "4-2-stable"
19
+ gem "rails", github: "rails/rails", branch: "4-2-stable"
20
20
 
21
21
  platforms :mri_21 do
22
22
  gem "byebug"
23
23
  end
24
24
 
25
- gemspec :path => "../"
25
+ gemspec path: "../"
@@ -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: "5-0-stable"
20
+
21
+ platforms :mri_21 do
22
+ gem "byebug"
23
+ end
24
+
25
+ gemspec path: "../"
@@ -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: "5-1-stable"
20
+
21
+ platforms :mri_21 do
22
+ gem "byebug"
23
+ end
24
+
25
+ gemspec path: "../"
@@ -16,11 +16,11 @@ gem "poltergeist"
16
16
  gem "sqlite3"
17
17
  gem "appraisal"
18
18
  gem "launchy"
19
- gem "rails", :github => "rails/rails"
20
- gem "arel", :github => "rails/arel"
19
+ gem "rails", github: "rails/rails"
20
+ gem "arel", github: "rails/arel"
21
21
 
22
22
  platforms :mri_21 do
23
23
  gem "byebug"
24
24
  end
25
25
 
26
- gemspec :path => "../"
26
+ gemspec path: "../"
@@ -93,6 +93,9 @@ BestInPlaceEditor.prototype = {
93
93
 
94
94
  update: function () {
95
95
  'use strict';
96
+
97
+ this.element.trigger(jQuery.Event("best_in_place:before-update"));
98
+
96
99
  var editor = this,
97
100
  value = this.getValue();
98
101
 
@@ -103,7 +106,7 @@ BestInPlaceEditor.prototype = {
103
106
  }
104
107
 
105
108
  editor.ajax({
106
- "type": BestInPlaceEditor.defaults.ajaxMethod,
109
+ "type": this.requestMethod(),
107
110
  "dataType": BestInPlaceEditor.defaults.ajaxDataType,
108
111
  "data": editor.requestData(),
109
112
  "success": function (data, status, xhr) {
@@ -143,8 +146,6 @@ BestInPlaceEditor.prototype = {
143
146
  editor.element.attr('data-bip-value', value);
144
147
 
145
148
  editor.element.trigger(jQuery.Event("best_in_place:update"));
146
-
147
-
148
149
  },
149
150
 
150
151
  activateForm: function () {
@@ -189,6 +190,8 @@ BestInPlaceEditor.prototype = {
189
190
  self.cancelButton = self.element.data("bipCancelButton") || self.cancelButton;
190
191
  self.cancelButtonClass = self.element.data("bipCancelButtonClass") || self.cancelButtonClass || BestInPlaceEditor.defaults.cancelButtonClass;
191
192
  self.skipBlur = self.element.data("bipSkipBlur") || self.skipBlur || BestInPlaceEditor.defaults.skipBlur;
193
+ self.isNewObject = self.element.data("bipNewObject");
194
+ self.dataExtraPayload = self.element.data("bipExtraPayload");
192
195
 
193
196
  // Fix for default values of 0
194
197
  if (self.element.data("bipPlaceholder") == null) {
@@ -246,6 +249,11 @@ BestInPlaceEditor.prototype = {
246
249
  return jQuery.trim(s);
247
250
  },
248
251
 
252
+ requestMethod: function() {
253
+ 'use strict';
254
+ return this.isNewObject ? 'post' : BestInPlaceEditor.defaults.ajaxMethod;
255
+ },
256
+
249
257
  /* Generate the data sent in the POST request */
250
258
  requestData: function () {
251
259
  'use strict';
@@ -253,13 +261,17 @@ BestInPlaceEditor.prototype = {
253
261
  var csrf_token = jQuery('meta[name=csrf-token]').attr('content'),
254
262
  csrf_param = jQuery('meta[name=csrf-param]').attr('content');
255
263
 
256
- var data = "_method=" + BestInPlaceEditor.defaults.ajaxMethod;
257
- data += "&" + this.objectName + '[' + this.attributeName + ']=' + encodeURIComponent(this.getValue());
264
+ var data = {}
265
+ data['_method'] = this.requestMethod()
266
+
267
+ data[this.objectName] = this.dataExtraPayload || {}
268
+
269
+ data[this.objectName][this.attributeName] = this.getValue()
258
270
 
259
271
  if (csrf_param !== undefined && csrf_token !== undefined) {
260
- data += "&" + csrf_param + "=" + encodeURIComponent(csrf_token);
272
+ data[csrf_param] = csrf_token
261
273
  }
262
- return data;
274
+ return jQuery.param(data);
263
275
  },
264
276
 
265
277
  ajax: function (options) {
@@ -289,6 +301,12 @@ BestInPlaceEditor.prototype = {
289
301
  this.element.data('bip-original-content', this.element.text());
290
302
  this.element.html(response.display_as);
291
303
  }
304
+ if (this.isNewObject && response && response[this.objectName]) {
305
+ if (response[this.objectName]["id"]) {
306
+ this.isNewObject = false
307
+ this.url += "/" + response[this.objectName]["id"] // in REST a POST /thing url should become PUT /thing/123
308
+ }
309
+ }
292
310
  }
293
311
  this.element.toggleClass('bip-placeholder', this.isPlaceHolder());
294
312
 
@@ -469,7 +487,10 @@ BestInPlaceEditor.forms = {
469
487
  var option_elt = jQuery(document.createElement('option'))
470
488
  .val(key)
471
489
  .html(value);
472
- if (String(key) === String(currentCollectionValue)) option_elt.attr('selected', 'selected');
490
+
491
+ if (currentCollectionValue) {
492
+ if (String(key) === String(currentCollectionValue)) option_elt.attr('selected', 'selected');
493
+ }
473
494
  select_elt.append(option_elt);
474
495
  });
475
496
  output.append(select_elt);
@@ -50,6 +50,12 @@ module BestInPlace
50
50
 
51
51
  options[:data]['bip-url'] = url_for(opts[:url] || object)
52
52
 
53
+ if real_object.respond_to?(:new_record?) and real_object.new_record?
54
+ options[:data]['bip-new-object'] = true
55
+ # collect name => value map of unsaved attributes to be serialized
56
+ options[:data]['bip-extra-payload'] = Hash[real_object.changes.map { |k,v| [k, v[1]] }]
57
+ end
58
+
53
59
  options[:data]['bip-confirm'] = opts[:confirm].presence
54
60
  options[:data]['bip-value'] = html_escape(value).presence
55
61
 
@@ -44,7 +44,7 @@ module BestInPlace
44
44
  evaluate_script('!window.jQuery') || evaluate_script('jQuery.active').zero?
45
45
  end
46
46
 
47
- def wait_until(max_execution_time_in_seconds = Capybara.default_wait_time)
47
+ def wait_until(max_execution_time_in_seconds = Capybara.default_max_wait_time)
48
48
  Timeout.timeout(max_execution_time_in_seconds) do
49
49
  loop do
50
50
  if yield
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
@@ -277,6 +277,39 @@ describe BestInPlace::Helper, type: :helper do
277
277
  end
278
278
  end
279
279
 
280
+ context "with a new record and associations" do
281
+ before do
282
+ @user.save
283
+ @test_result = TestResult.new name: 'Meyers-Briggs', user_id: @user.id
284
+ end
285
+
286
+ describe "url generation" do
287
+ it "should have the correct default url" do
288
+ nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @test_result], :result)
289
+ span = nk.css("span")
290
+ expect(span.attribute("data-bip-url").value).to eq("/admin/test_results")
291
+ end
292
+
293
+ it "should set the new-object data param" do
294
+ nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @test_result], :result)
295
+ span = nk.css("span")
296
+ expect(span.attribute("data-bip-new-object").value).to be_truthy
297
+ end
298
+
299
+ it "should set the extra-payload data param to a hash of all the unsaved attribs of the model" do
300
+ nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @test_result], :result)
301
+ span = nk.css("span")
302
+ expect(span.attribute("data-bip-extra-payload").value).to eq %Q!{"name":"Meyers-Briggs","user_id":#{@user.id}}!
303
+ end
304
+
305
+ it "should have a proper DOM id for the container" do
306
+ nk = Nokogiri::HTML.parse(helper.best_in_place [:admin, @test_result], :result)
307
+ span = nk.css("span")
308
+ expect(span.attribute("id").value).to eq("best_in_place_test_result_result")
309
+ end
310
+ end
311
+ end
312
+
280
313
  context "with a text field attribute" do
281
314
  before do
282
315
  nk = Nokogiri::HTML.parse(helper.best_in_place @user, :name)
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ describe "with new records", :js => true do
4
+ before do
5
+ @user = User.new :name => "Julian",
6
+ :last_name => "Bronson",
7
+ :email => "jbro@example.com",
8
+ :address => '1925 Park Ave',
9
+ :zip => '10001',
10
+ :description => 'Excellent at taking tests.'
11
+ end
12
+
13
+ it "should create new records with proper associations" do
14
+ @user.save!
15
+ expect(@user.test_results.length).to eq 0
16
+
17
+ visit admin_user_path(@user)
18
+ expect(find('#test-results-table')).to have_content('Meyers-Briggs')
19
+ expect(find('#test-results-table')).to have_content('Stanford-Binet')
20
+ expect(find('#test-results-table')).to have_content('SAT')
21
+
22
+ bip_text 'test_result_sat', :result, "1700"
23
+ bip_text 'test_result_stanford_binet', :result, "120"
24
+ bip_select 'test_result_meyers_briggs', :result, "INFJ"
25
+
26
+ @user.reload
27
+ expect(@user.test_results.length).to eq 3
28
+
29
+ visit admin_user_path(@user)
30
+
31
+ expect(find('#best_in_place_test_result_sat_result')).to have_content('1700')
32
+ expect(find('#best_in_place_test_result_stanford_binet_result')).to have_content('120')
33
+ expect(find('#best_in_place_test_result_meyers_briggs_result')).to have_content('INFJ')
34
+ end
35
+
36
+ it "should update persisted records as well" do
37
+ @user.save!
38
+ test_result = TestResult.new name: 'SAT', result: '1310', user_id: @user.id
39
+ test_result.save!
40
+
41
+ visit admin_user_path(@user)
42
+ expect(find('#best_in_place_test_result_sat_result')).to have_content('1310')
43
+
44
+ bip_text 'test_result_sat', :result, "1410"
45
+ bip_select 'test_result_meyers_briggs', :result, "ISFP"
46
+
47
+ visit admin_user_path(@user)
48
+
49
+ expect(find('#best_in_place_test_result_sat_result')).to have_content('1410')
50
+ expect(find('#best_in_place_test_result_meyers_briggs_result')).to have_content('ISFP')
51
+ end
52
+
53
+ it "should create new records then change the bip instance to updating the persited record" do
54
+ @user.save!
55
+
56
+ visit admin_user_path(@user)
57
+ bip_text 'test_result_stanford_binet', :result, "110"
58
+
59
+ @user.reload
60
+ expect(@user.test_results.length).to eq 1
61
+ expect(@user.test_results.first.result).to eq "110"
62
+
63
+ bip_text 'test_result_stanford_binet', :result, "120"
64
+
65
+ @user.test_results.reload
66
+ expect(@user.test_results.length).to eq 1
67
+ expect(@user.test_results.first.result).to eq "120"
68
+ end
69
+
70
+ end
@@ -0,0 +1,5 @@
1
+ /*
2
+ *= require scaffold.css
3
+ *= require style.css
4
+ *= require jquery-ui-1.8.16.custom.css
5
+ */
@@ -0,0 +1,22 @@
1
+ class Admin::TestResultsController < ApplicationController
2
+
3
+ def create
4
+ test_result = TestResult.new test_result_params
5
+ test_result.save!
6
+ render json: test_result, root: true
7
+ end
8
+
9
+ def update
10
+ @test_result = TestResult.find(params[:id])
11
+ @test_result.update_attributes(test_result_params)
12
+ respond_to do |format|
13
+ format.json { respond_with_bip(@test_result) }
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def test_result_params
20
+ params[:test_result].permit!
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ class TestResult < ActiveRecord::Base
2
+ belongs_to :user
3
+
4
+ AVAILABLE_TESTS = %w(Meyers-Briggs Stanford-Binet SAT)
5
+
6
+ def name_to_slug
7
+ name.downcase.gsub(/\W/, '_')
8
+ end
9
+
10
+ def options
11
+ if name == 'Meyers-Briggs'
12
+ %w( ISTJ ISFJ INFJ INTJ ISTP ISFP ).map { |v| [v, v] }
13
+ end
14
+ end
15
+
16
+ end
@@ -21,6 +21,8 @@ class User < ActiveRecord::Base
21
21
  alias_attribute :receive_email_image, :receive_email
22
22
  alias_attribute :description_simple, :description
23
23
 
24
+ has_many :test_results
25
+
24
26
  def address_format
25
27
  "<b>addr => [#{address}]</b>".html_safe
26
28
  end
@@ -32,4 +34,10 @@ class User < ActiveRecord::Base
32
34
  def zip_format
33
35
  nil
34
36
  end
37
+
38
+ def tests
39
+ TestResult::AVAILABLE_TESTS.map do |test_type|
40
+ test_results.where(name: test_type).first || TestResult.new(name: test_type, user_id: id)
41
+ end
42
+ end
35
43
  end
@@ -16,5 +16,19 @@
16
16
  </td>
17
17
  </tr>
18
18
  </table>
19
+
20
+ <table id="test-results-table">
21
+ <% @user.tests.each do |test| %>
22
+ <tr>
23
+ <td><%= test.name %></td>
24
+ <td>
25
+ <%= best_in_place [:admin, test], :result, as: test.options ? :select : :input,
26
+ collection: test.options,
27
+ id: "best_in_place_test_result_#{test.name_to_slug}_result"
28
+ %>
29
+ </td>
30
+ </tr>
31
+ <% end %>
32
+ </table>
19
33
  </div>
20
34
 
@@ -2,7 +2,7 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Best In Place TEST APP <%= Rails::VERSION::STRING %></title>
5
- <%= stylesheet_link_tag "scaffold", "style", "jquery-ui-1.8.16.custom" %>
5
+ <%= stylesheet_link_tag "application" %>
6
6
  <%= javascript_include_tag "application" %>
7
7
  <%= csrf_meta_tag %>
8
8
  </head>
@@ -13,6 +13,7 @@ Rails.application.routes.draw do
13
13
 
14
14
  namespace :admin do
15
15
  resources :users
16
+ resources :test_results, only: [:create, :update]
16
17
  end
17
18
 
18
19
  root :to => "users#index"
@@ -24,4 +24,10 @@ ActiveRecord::Schema.define do
24
24
  t.string "favorite_locale"
25
25
  t.integer "zero_field"
26
26
  end
27
+
28
+ create_table "test_results", :force => true do |t|
29
+ t.string "name"
30
+ t.string "result"
31
+ t.integer "user_id"
32
+ end
27
33
  end
@@ -12,8 +12,12 @@ Capybara.javascript_driver = :poltergeist
12
12
 
13
13
  require 'best_in_place'
14
14
 
15
- Combustion.initialize! :active_record, :action_controller,
16
- :action_view, :sprockets
15
+ Combustion.initialize! :active_record, :action_controller, :action_view, :sprockets do
16
+ config.assets.compile = true
17
+ config.assets.compress = false
18
+ config.assets.debug = false
19
+ config.assets.digest = false
20
+ end
17
21
 
18
22
  require 'rspec/rails'
19
23
  require 'capybara/rails'
@@ -26,4 +30,7 @@ RSpec.configure do |config|
26
30
  config.include BestInPlace::TestHelpers
27
31
  config.use_transactional_fixtures = false
28
32
  config.raise_errors_for_deprecations!
33
+
34
+ config.filter_run focus: true
35
+ config.run_all_when_everything_filtered = true
29
36
  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.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernat Farrero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -62,6 +62,8 @@ files:
62
62
  - gemfiles/rails_4.0.gemfile
63
63
  - gemfiles/rails_4.1.gemfile
64
64
  - gemfiles/rails_4.2.gemfile
65
+ - gemfiles/rails_5.0.gemfile
66
+ - gemfiles/rails_5.1.gemfile
65
67
  - gemfiles/rails_edge.gemfile
66
68
  - lib/assets/javascripts/best_in_place.jquery-ui.js
67
69
  - lib/assets/javascripts/best_in_place.js
@@ -79,6 +81,7 @@ files:
79
81
  - spec/integration/double_init_spec.rb
80
82
  - spec/integration/js_spec.rb
81
83
  - spec/integration/live_spec.rb
84
+ - spec/integration/new_record_spec.rb
82
85
  - spec/integration/placeholder_spec.rb
83
86
  - spec/integration/text_area_spec.rb
84
87
  - spec/internal/app/assets/images/info.png
@@ -104,9 +107,11 @@ files:
104
107
  - spec/internal/app/assets/images/yes.png
105
108
  - spec/internal/app/assets/javascripts/application.js
106
109
  - spec/internal/app/assets/stylesheets/.gitkeep
110
+ - spec/internal/app/assets/stylesheets/application.css
107
111
  - spec/internal/app/assets/stylesheets/jquery-ui-1.8.16.custom.css.erb
108
112
  - spec/internal/app/assets/stylesheets/scaffold.css
109
113
  - spec/internal/app/assets/stylesheets/style.css
114
+ - spec/internal/app/controllers/admin/test_results_controller.rb
110
115
  - spec/internal/app/controllers/admin/users_controller.rb
111
116
  - spec/internal/app/controllers/application_controller.rb
112
117
  - spec/internal/app/controllers/cuca/cars_controller.rb
@@ -114,6 +119,7 @@ files:
114
119
  - spec/internal/app/helpers/application_helper.rb
115
120
  - spec/internal/app/helpers/users_helper.rb
116
121
  - spec/internal/app/models/cuca/car.rb
122
+ - spec/internal/app/models/test_result.rb
117
123
  - spec/internal/app/models/user.rb
118
124
  - spec/internal/app/views/admin/users/show.html.erb
119
125
  - spec/internal/app/views/cuca/cars/show.html.erb
@@ -158,10 +164,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
164
  version: '0'
159
165
  requirements: []
160
166
  rubyforge_project:
161
- rubygems_version: 2.4.8
167
+ rubygems_version: 2.6.8
162
168
  signing_key:
163
169
  specification_version: 4
164
170
  summary: It makes any field in place editable by clicking on it, it works for inputs,
165
171
  textareas, select dropdowns and checkboxes
166
172
  test_files: []
167
- has_rdoc: