Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method option to allow for POST requests #597

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions gemfiles/rails_3.2.gemfile

This file was deleted.

6 changes: 4 additions & 2 deletions gemfiles/rails_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions gemfiles/rails_4.1.gemfile → gemfiles/rails_5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions gemfiles/rails_4.0.gemfile → gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion lib/assets/javascripts/best_in_place.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
7 changes: 5 additions & 2 deletions lib/best_in_place/engine.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/best_in_place/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/best_in_place/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 12 additions & 4 deletions lib/best_in_place/test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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? }
Expand Down
3 changes: 3 additions & 0 deletions spec/internal/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/internal/app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/internal/app/controllers/cuca/cars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/internal/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down