diff --git a/.travis.yml b/.travis.yml index a3a01bd6..5c370e16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,30 +2,41 @@ language: ruby sudo: false cache: bundler rvm: - - 2.4.1 - - 2.3.3 - 2.2.7 + - 2.3.3 + - 2.4.1 + - 2.5.7 + - 2.6.5 env: "RAILS_ENV=test DISPLAY=:99.0" gemfile: - - gemfiles/rails_3.2.gemfile - - gemfiles/rails_4.0.gemfile - - gemfiles/rails_4.1.gemfile - gemfiles/rails_4.2.gemfile - gemfiles/rails_5.0.gemfile - gemfiles/rails_5.1.gemfile + - gemfiles/rails_5.2.gemfile + - gemfiles/rails_6.0.gemfile - gemfiles/rails_edge.gemfile matrix: allow_failures: - gemfile: gemfiles/rails_edge.gemfile exclude: + - rvm: 2.2.7 + gemfile: gemfiles/rails_5.2.gemfile + - rvm: 2.2.7 + gemfile: gemfiles/rails_6.0.gemfile + - rvm: 2.2.7 + gemfile: gemfiles/rails_edge.gemfile + - rvm: 2.3.3 + gemfile: gemfiles/rails_5.2.gemfile + - rvm: 2.3.3 + gemfile: gemfiles/rails_6.0.gemfile + - rvm: 2.3.3 + gemfile: gemfiles/rails_edge.gemfile - rvm: 2.4.1 - gemfile: gemfiles/rails_3.2.gemfile - - rvm: 2.4.1 - gemfile: gemfiles/rails_4.0.gemfile + gemfile: gemfiles/rails_6.0.gemfile - rvm: 2.4.1 - gemfile: gemfiles/rails_4.1.gemfile + gemfile: gemfiles/rails_edge.gemfile before_install: - mkdir travis-phantomjs diff --git a/Appraisals b/Appraisals index b259b7ce..928d05ee 100644 --- a/Appraisals +++ b/Appraisals @@ -1,31 +1,32 @@ -appraise "rails-3.2" do - gem 'rails', github: "rails/rails", branch: '3-2-stable' - gem 'strong_parameters' - gem 'test-unit' +appraise 'rails-4.2' do + gem 'bundler', '~> 1.3' + gem 'rails', github: 'rails/rails', branch: '4-2-stable' + gem 'rspec-rails', '~> 3' + gem 'sqlite3', '~> 1.3.6' end -appraise "rails-4.0" do - gem "rails", github: "rails/rails", branch: '4-0-stable' - gem 'test-unit' +appraise 'rails-5.0' do + gem 'rails', github: 'rails/rails', branch: '5-0-stable' + gem 'sqlite3', '~> 1.3.6' end -appraise "rails-4.1" do - gem "rails", github: "rails/rails", branch: '4-1-stable' +appraise 'rails-5.1' do + gem 'rails', github: 'rails/rails', branch: '5-1-stable' + gem 'sqlite3' end -appraise "rails-4.2" do - gem "rails", github: "rails/rails", branch: '4-2-stable' +appraise 'rails-5.2' do + gem 'rails', github: 'rails/rails', branch: '5-2-stable' + gem 'sqlite3' end -appraise "rails-5.0" do - gem "rails", github: "rails/rails", branch: '5-0-stable' +appraise 'rails-6.0' do + gem 'rails', github: 'rails/rails', branch: '6-0-stable' + gem 'sqlite3' end -appraise "rails-5.1" do - gem "rails", github: "rails/rails", branch: '5-1-stable' -end - -appraise "rails-edge" do - gem "rails", github: "rails/rails" +appraise 'rails-edge' do + gem 'rails', github: 'rails/rails' gem 'arel', github: 'rails/arel' + gem 'sqlite3' end diff --git a/Gemfile b/Gemfile index 588f4b4c..0491e62d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,9 +14,9 @@ gem 'combustion' gem 'sprockets-rails' gem 'capybara' gem 'poltergeist' -gem 'sqlite3' gem 'appraisal' gem 'launchy' +gem 'webrick' platforms :mri_21 do gem 'byebug' diff --git a/README.md b/README.md index 2f753416..57477102 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Options: - **:as** It can be only [:input, :textarea, :select, :checkbox, :date] or if undefined it defaults to :input. - **: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. - **:url**: URL to which the updating action will be sent. If not defined it defaults to the :object path. +- **:method**: HTTP method to be used for the request. Defaults to :put - **: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". If not defined it will show *"-"*. - **:activator**: Is the DOM object that can activate the field. If not defined the user will making editable by clicking on it. @@ -216,7 +217,7 @@ def update @user = User.find params[:id] respond_to do |format| - if @user.update_attributes(params[:user]) + if @user.update(params[:user]) format.html { redirect_to(@user, :notice => 'User was successfully updated.') } format.json { respond_with_bip(@user) } else diff --git a/gemfiles/rails_3.2.gemfile b/gemfiles/rails_3.2.gemfile deleted file mode 100644 index 5db50a14..00000000 --- a/gemfiles/rails_3.2.gemfile +++ /dev/null @@ -1,27 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" -source "https://rails-assets.org" - -gem "activerecord" -gem "rails-assets-jquery", "1.11.1" -gem "rails-assets-jquery-ui", "1.10.4" -gem "rdiscount" -gem "rspec-rails" -gem "nokogiri" -gem "combustion" -gem "sprockets-rails" -gem "capybara" -gem "poltergeist" -gem "sqlite3" -gem "appraisal" -gem "launchy" -gem "rails", github: "rails/rails", branch: "3-2-stable" -gem "strong_parameters" -gem "test-unit" - -platforms :mri_21 do - gem "byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile index b54932d0..8f9e626b 100644 --- a/gemfiles/rails_4.2.gemfile +++ b/gemfiles/rails_4.2.gemfile @@ -7,16 +7,18 @@ gem "activerecord" gem "rails-assets-jquery", "1.11.1" gem "rails-assets-jquery-ui", "1.10.4" gem "rdiscount" -gem "rspec-rails" +gem "rspec-rails", "~> 3" gem "nokogiri" gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" +gem "webrick" +gem "bundler", "~> 1.3" gem "rails", github: "rails/rails", branch: "4-2-stable" +gem "sqlite3", "~> 1.3.6" platforms :mri_21 do gem "byebug" diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile index eeb6e518..d3c0bc0c 100644 --- a/gemfiles/rails_5.0.gemfile +++ b/gemfiles/rails_5.0.gemfile @@ -13,10 +13,11 @@ gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" +gem "webrick" gem "rails", github: "rails/rails", branch: "5-0-stable" +gem "sqlite3", "~> 1.3.6" platforms :mri_21 do gem "byebug" diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_5.1.gemfile index b381a16e..e0375530 100644 --- a/gemfiles/rails_5.1.gemfile +++ b/gemfiles/rails_5.1.gemfile @@ -13,10 +13,11 @@ gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" +gem "webrick" gem "rails", github: "rails/rails", branch: "5-1-stable" +gem "sqlite3" platforms :mri_21 do gem "byebug" diff --git a/gemfiles/rails_4.1.gemfile b/gemfiles/rails_5.2.gemfile similarity index 85% rename from gemfiles/rails_4.1.gemfile rename to gemfiles/rails_5.2.gemfile index 4b0e2757..e9d7c138 100644 --- a/gemfiles/rails_4.1.gemfile +++ b/gemfiles/rails_5.2.gemfile @@ -13,10 +13,11 @@ gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" -gem "rails", github: "rails/rails", branch: "4-1-stable" +gem "webrick" +gem "rails", github: "rails/rails", branch: "5-2-stable" +gem "sqlite3" platforms :mri_21 do gem "byebug" diff --git a/gemfiles/rails_4.0.gemfile b/gemfiles/rails_6.0.gemfile similarity index 85% rename from gemfiles/rails_4.0.gemfile rename to gemfiles/rails_6.0.gemfile index 99808b83..c29f133d 100644 --- a/gemfiles/rails_4.0.gemfile +++ b/gemfiles/rails_6.0.gemfile @@ -13,11 +13,11 @@ gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" -gem "rails", github: "rails/rails", branch: "4-0-stable" -gem "test-unit" +gem "webrick" +gem "rails", github: "rails/rails", branch: "6-0-stable" +gem "sqlite3" platforms :mri_21 do gem "byebug" diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile index bb351225..7ee7da60 100644 --- a/gemfiles/rails_edge.gemfile +++ b/gemfiles/rails_edge.gemfile @@ -13,11 +13,12 @@ gem "combustion" gem "sprockets-rails" gem "capybara" gem "poltergeist" -gem "sqlite3" gem "appraisal" gem "launchy" +gem "webrick" gem "rails", github: "rails/rails" gem "arel", github: "rails/arel" +gem "sqlite3" platforms :mri_21 do gem "byebug" diff --git a/lib/assets/javascripts/best_in_place.js b/lib/assets/javascripts/best_in_place.js index a6184f16..07ed116c 100644 --- a/lib/assets/javascripts/best_in_place.js +++ b/lib/assets/javascripts/best_in_place.js @@ -170,6 +170,7 @@ BestInPlaceEditor.prototype = { self.element.parents().each(function () { var $parent = jQuery(this); self.url = self.url || $parent.data("bipUrl"); + self.ajaxMethod = self.ajaxMethod || $parent.data("bipMethod"); self.activator = self.activator || $parent.data("bipActivator"); self.okButton = self.okButton || $parent.data("bipOkButton"); self.okButtonClass = self.okButtonClass || $parent.data("bipOkButtonClass"); @@ -180,6 +181,7 @@ BestInPlaceEditor.prototype = { // Load own attributes (overrides all others) self.url = self.element.data("bipUrl") || self.url || document.location.pathname; + self.ajaxMethod = self.element.data("bipMethod") || BestInPlaceEditor.defaults.ajaxMethod; self.collection = self.element.data("bipCollection") || self.collection; self.formType = self.element.data("bipType") || "input"; self.objectName = self.element.data("bipObject") || self.objectName; @@ -251,7 +253,7 @@ BestInPlaceEditor.prototype = { requestMethod: function() { 'use strict'; - return this.isNewObject ? 'post' : BestInPlaceEditor.defaults.ajaxMethod; + return this.isNewObject ? 'post' : this.ajaxMethod; }, /* Generate the data sent in the POST request */ diff --git a/lib/best_in_place/engine.rb b/lib/best_in_place/engine.rb index 1f1c5b5c..a9d4d52e 100644 --- a/lib/best_in_place/engine.rb +++ b/lib/best_in_place/engine.rb @@ -1,8 +1,11 @@ module BestInPlace class Engine < Rails::Engine initializer 'best_in_place' do - ActionView::Base.send(:include, BestInPlace::Helper) - ActionController::Base.send(:include, BestInPlace::ControllerExtensions) + ActiveSupport.on_load(:action_controller) do + ActionView::Base.send(:include, BestInPlace::Helper) + + ActionController::Base.send(:include, BestInPlace::ControllerExtensions) + end end end end diff --git a/lib/best_in_place/helper.rb b/lib/best_in_place/helper.rb index e9be0795..bef04ce1 100644 --- a/lib/best_in_place/helper.rb +++ b/lib/best_in_place/helper.rb @@ -49,6 +49,7 @@ def best_in_place(object, field, opts = {}) options[:data]['bip-skip-blur'] = opts.has_key?(:skip_blur) ? opts[:skip_blur].presence : BestInPlace.skip_blur options[:data]['bip-url'] = url_for(opts[:url] || object) + options[:data]['bip-method'] = opts[:method] unless opts[:method].blank? if real_object.respond_to?(:new_record?) and real_object.new_record? options[:data]['bip-new-object'] = true diff --git a/lib/best_in_place/railtie.rb b/lib/best_in_place/railtie.rb index f67e191b..c2c7dda0 100644 --- a/lib/best_in_place/railtie.rb +++ b/lib/best_in_place/railtie.rb @@ -4,7 +4,7 @@ module BestInPlace class Railtie < ::Rails::Railtie #:nodoc: config.after_initialize do - BestInPlace::ViewHelpers = ActionView::Base.new + BestInPlace::ViewHelpers = ActionView::Base.respond_to?(:empty) ? ActionView::Base.empty : ActionView::Base.new end end end diff --git a/lib/best_in_place/test_helpers.rb b/lib/best_in_place/test_helpers.rb index 87298a92..cf52d02d 100644 --- a/lib/best_in_place/test_helpers.rb +++ b/lib/best_in_place/test_helpers.rb @@ -4,7 +4,7 @@ module TestHelpers def bip_area(model, attr, new_value) id = BestInPlace::Utils.build_best_in_place_id model, attr - find("##{id}").click + click_bip_input(id) execute_script <<-JS $("##{id} form textarea").val('#{escape_javascript new_value.to_s}'); $("##{id} form textarea").blur(); @@ -14,7 +14,7 @@ def bip_area(model, attr, new_value) def bip_text(model, attr, new_value) id = BestInPlace::Utils.build_best_in_place_id model, attr - find("##{id}").click + click_bip_input(id) execute_script <<-JS $("##{id} input[name='#{attr}']").val('#{escape_javascript new_value.to_s}'); $("##{id} form").submit(); @@ -24,17 +24,25 @@ def bip_text(model, attr, new_value) def bip_bool(model, attr) id = BestInPlace::Utils.build_best_in_place_id model, attr - find("##{id}").click + click_bip_input(id) wait_for_ajax end def bip_select(model, attr, name) id = BestInPlace::Utils.build_best_in_place_id model, attr - find("##{id}").click + click_bip_input(id) find("##{id}").select(name) wait_for_ajax end + def click_bip_input(id) + if Capybara.current_driver == :poltergeist + find("##{id}").trigger('click') + else + find("##{id}").click + end + end + def wait_for_ajax return unless respond_to?(:evaluate_script) wait_until { finished_all_ajax_requests? } diff --git a/spec/internal/app/assets/config/manifest.js b/spec/internal/app/assets/config/manifest.js new file mode 100644 index 00000000..b16e53d6 --- /dev/null +++ b/spec/internal/app/assets/config/manifest.js @@ -0,0 +1,3 @@ +//= link_tree ../images +//= link_directory ../javascripts .js +//= link_directory ../stylesheets .css diff --git a/spec/internal/app/controllers/admin/test_results_controller.rb b/spec/internal/app/controllers/admin/test_results_controller.rb index d88e2e86..b8eed90b 100644 --- a/spec/internal/app/controllers/admin/test_results_controller.rb +++ b/spec/internal/app/controllers/admin/test_results_controller.rb @@ -8,7 +8,7 @@ def create def update @test_result = TestResult.find(params[:id]) - @test_result.update_attributes(test_result_params) + @test_result.update(test_result_params) respond_to do |format| format.json { respond_with_bip(@test_result) } end diff --git a/spec/internal/app/controllers/admin/users_controller.rb b/spec/internal/app/controllers/admin/users_controller.rb index 4a023a93..6746c0d9 100644 --- a/spec/internal/app/controllers/admin/users_controller.rb +++ b/spec/internal/app/controllers/admin/users_controller.rb @@ -6,7 +6,7 @@ def show def update @user = User.find(params[:id]) respond_to do |format| - @user.update_attributes(user_params) + @user.update(user_params) format.json { respond_with_bip(@user, param: :admin) } end end diff --git a/spec/internal/app/controllers/cuca/cars_controller.rb b/spec/internal/app/controllers/cuca/cars_controller.rb index e273352c..bfae3d7f 100644 --- a/spec/internal/app/controllers/cuca/cars_controller.rb +++ b/spec/internal/app/controllers/cuca/cars_controller.rb @@ -8,7 +8,7 @@ def update @car = Car.find params[:id] respond_to do |format| - @car.update_attributes params[:cuca_car] + @car.update params[:cuca_car] format.json { respond_with_bip(@car) } end end diff --git a/spec/internal/app/controllers/users_controller.rb b/spec/internal/app/controllers/users_controller.rb index 29d30881..449c4758 100644 --- a/spec/internal/app/controllers/users_controller.rb +++ b/spec/internal/app/controllers/users_controller.rb @@ -48,7 +48,7 @@ def update @user = User.find(params[:id]) respond_to do |format| - if @user.update_attributes(user_params) + if @user.update(user_params) format.html { redirect_to(@user, :notice => 'User was successfully updated.') } format.json { respond_with_bip(@user) } else diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index edac56bb..d2c18991 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,6 +9,7 @@ Capybara::Poltergeist::Driver.new(app, {js_errors: false, inspector: true}) end Capybara.javascript_driver = :poltergeist +Capybara.server = :webrick require 'best_in_place'