Skip to content

Commit

Permalink
Updates for rails5 and deprecation notices
Browse files Browse the repository at this point in the history
  • Loading branch information
twalpole committed Feb 19, 2016
1 parent 221ceae commit b131f73
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1.1
- 2.2.2
- ruby-head
- jruby-19mode

Expand All @@ -14,8 +15,10 @@ gemfile:
- gemfiles/4.0.gemfile
- gemfiles/4.1.gemfile
- gemfiles/4.2.gemfile

matrix:
include:
- gemfile: gemfiles/5.0.beta2.gemfile
rvm: 2.2.2
allow_failures:
- gemfile: gemfiles/3.0.gemfile
rvm: 2.0.0
Expand Down
5 changes: 5 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ appraise "4.2" do
gem "rails", "~> 4.2"
gemspec
end

appraise "5.0.beta2" do
gem "rails", "~> 5.0.0.beta2"
gemspec
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ es:
It would also be a good idea to create a english version under `config/locales/en.yml` or your english speaking friends will get errors. If your app already uses I18n you don't need to do anything else, if not you will need to make sure that you set the `I18n.locale` on each request you could do this somewhere like a before filter in your application_controller.rb

```ruby
before_filter :set_locale
before_action :set_locale

private

Expand Down
12 changes: 12 additions & 0 deletions gemfiles/5.0.beta2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 5.0.0.beta2"

group :development, :test do
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", :platform => :jruby
end

gemspec :path => "../"
1 change: 1 addition & 0 deletions lib/wicked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class WickedProtectedStepError < WickedError; end
require 'wicked/controller/concerns/render_redirect'
require 'wicked/controller/concerns/steps'
require 'wicked/controller/concerns/path'
require 'wicked/controller/concerns/action'
require 'wicked/wizard'
require 'wicked/wizard/translated'
require 'wicked/engine'
13 changes: 13 additions & 0 deletions lib/wicked/controller/concerns/action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Wicked::Controller::Concerns::Action
extend ActiveSupport::Concern

module ClassMethods
def self.extended(base)
%w{before skip_before prepend_before}.each do |action|
define_method "#{action}_action" do |*names, &blk|
send("#{action}_filter", *names, &blk)
end unless base.respond_to? "#{action}_action"
end
end
end
end
1 change: 1 addition & 0 deletions lib/wicked/controller/concerns/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def wicked_action


def wizard_path(goto_step = nil, options = {})
options = options.to_h if options.respond_to?(:permitted?) && options.respond_to?(:to_h)
options = { :controller => wicked_controller,
:action => 'show',
:id => goto_step || params[:id],
Expand Down
2 changes: 1 addition & 1 deletion lib/wicked/controller/concerns/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def steps(*args)
options = args.extract_options!
steps = args
check_protected!(steps)
prepend_before_filter(options) do
prepend_before_action(options) do
self.steps = steps.dup
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/wicked/wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@ def initialize

class UndefinedStepsError < RuntimeError
def initialize
super "No step definitions have been supplied; if setting via `before_filter`, use `prepend_before_filter`"
super "No step definitions have been supplied; if setting via `before_action`, use `prepend_before_action`"
end
end

# Include the modules!!

include Wicked::Controller::Concerns::Path
include Wicked::Controller::Concerns::RenderRedirect
include Wicked::Controller::Concerns::Steps

included do
include Wicked::Controller::Concerns::Action
# Give our Views helper methods!
helper_method :wizard_path, :next_wizard_path, :previous_wizard_path,
:step, :wizard_steps, :current_step?,
:past_step?, :future_step?, :previous_step?,
:next_step?
# Set @step and @next_step variables
before_filter :setup_wizard
before_action :setup_wizard
end

# forward to first step with whatever params are provided
Expand Down
4 changes: 2 additions & 2 deletions lib/wicked/wizard/translated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Translated
include Wicked::Wizard

included do
skip_before_filter :setup_wizard
before_filter :setup_wizard_translated
skip_before_action :setup_wizard
before_action :setup_wizard_translated

helper_method :wizard_translate, :wizard_value
end
Expand Down
5 changes: 3 additions & 2 deletions test/controllers/bar_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require 'test_helper'

class BarControllerTest < ActionController::TestCase
class BarControllerTest < WickedControllerTestCase

test 'index redirects to the first step' do
get :index
assert_redirected_to bar_path(:first)
end

test 'index redirects to the first step, preserving query args' do
get :index, :some => 'arguments', :were => 'passed'
get :index, params: { :some => 'arguments', :were => 'passed' }
assert_redirected_to bar_path(:first, :some => 'arguments', :were => 'passed')
end
end
10 changes: 5 additions & 5 deletions test/controllers/updates_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
require 'test_helper'

class UpdatesControllerTest < ActionController::TestCase
class UpdatesControllerTest < WickedControllerTestCase
test 'redirect from first step to second step' do
put :update, :id => 'first'
put :update, params: {:id => 'first'}
assert_redirected_to update_path(:second)
assert_equal 'Thing was updated from step first.', flash[:notice]
end

test 'redirect from second step to final step' do
put :update, :id => 'second'
put :update, params: {:id => 'second'}
assert_redirected_to update_path(:last_step)
assert_equal 'Thing was updated from step second.', flash[:notice]
end

test 'redirect from last_step to root path' do
put :update, :id => 'last_step'
put :update, params: {:id => 'last_step'}
assert_redirected_to update_path(:wicked_finish)
assert_equal 'Thing was updated from step last_step.', flash[:notice]
end

test 'redirect from wicked_finish to root path' do
get :show, {:id => Wicked::FINISH_STEP}, {}, {:notice => "flash from last_step"}
get :show, params: {:id => Wicked::FINISH_STEP}, flash: {:notice => "flash from last_step"}
assert_redirected_to updates_path
assert_equal 'flash from last_step', flash[:notice]
end
Expand Down
7 changes: 5 additions & 2 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :pull_out_locale

if respond_to? :before_action
before_action :pull_out_locale
else
before_filter :pull_out_locale
end

def pull_out_locale
I18n.locale = params[:locale] if params[:locale].present?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class DynamicDifferentStepsController < ApplicationController
include Wicked::Wizard

before_filter :set_steps
before_filter :setup_wizard
before_action :set_steps
before_action :setup_wizard

def show
render_wizard
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/controllers/dynamic_steps_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class DynamicStepsController < ApplicationController
include Wicked::Wizard
prepend_before_filter :set_steps
prepend_before_action :set_steps

def show
render_wizard
Expand Down
11 changes: 9 additions & 2 deletions test/dummy/app/controllers/jump_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class JumpController < ApplicationController
steps :first, :second, :last_step

def show
skip_step(params[:skip_step_options]) if params[:skip_step]
jump_to :last_step, params[:skip_step_options] if params[:jump_to]
skip_step(skip_step_options) if params[:skip_step]
jump_to :last_step, skip_step_options if params[:jump_to]
if params[:resource]
value = params[:resource][:save] == 'true'
@bar = Bar.new(value)
Expand All @@ -19,4 +19,11 @@ def show
def update
end

private

def skip_step_options
options = params[:skip_step_options]
options.permit! if options.respond_to? :permitted?
options
end
end
2 changes: 2 additions & 0 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

config.active_support.test_order = :sorted
end
9 changes: 9 additions & 0 deletions test/support/wicked_controller_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class WickedControllerTestCase < ActionController::TestCase
if ActionPack::VERSION::MAJOR < 5
%w{get post put update}.each do |meth|
define_method meth do |action, args={}|
super(action, args[:params], args[:session], args[:flash])
end
end
end
end

0 comments on commit b131f73

Please sign in to comment.