stepper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +144 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/app/views/stepper/_fields.html.erb +17 -0
- data/config/locales/stepper.yml +6 -0
- data/lib/stepper.rb +3 -0
- data/lib/stepper/controllers/controller_additions.rb +75 -0
- data/lib/stepper/controllers/controller_resource.rb +58 -0
- data/lib/stepper/engine.rb +4 -0
- data/lib/stepper/exceptions.rb +4 -0
- data/lib/stepper/helper/action_view_additions.rb +14 -0
- data/lib/stepper/models/active_record_additions.rb +96 -0
- data/lib/stepper/railtie.rb +26 -0
- data/stepper.gemspec +136 -0
- data/test/controllers/controller_additions_test.rb +16 -0
- data/test/controllers/controller_resource_test.rb +49 -0
- data/test/controllers/controller_test.rb +138 -0
- data/test/helper.rb +20 -0
- data/test/helpers/helper_test.rb +49 -0
- data/test/integration/steps_test.rb +39 -0
- data/test/models/assigns_test.rb +15 -0
- data/test/models/instance_test.rb +65 -0
- data/test/models/models_test.rb +26 -0
- data/test/models/validation_test.rb +36 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/rails_app/app/controllers/companies_controller.rb +11 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/mailers/.gitkeep +0 -0
- data/test/rails_app/app/models/.gitkeep +0 -0
- data/test/rails_app/app/models/company.rb +18 -0
- data/test/rails_app/app/models/users.rb +3 -0
- data/test/rails_app/app/views/companies/_step1_step.html.erb +2 -0
- data/test/rails_app/app/views/companies/_step2_step.html.erb +2 -0
- data/test/rails_app/app/views/companies/_step3_step.html.erb +2 -0
- data/test/rails_app/app/views/companies/index.html.erb +1 -0
- data/test/rails_app/app/views/companies/new.html.erb +14 -0
- data/test/rails_app/app/views/companies/show.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +43 -0
- data/test/rails_app/config/boot.rb +6 -0
- data/test/rails_app/config/database.yml +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +30 -0
- data/test/rails_app/config/environments/production.rb +60 -0
- data/test/rails_app/config/environments/test.rb +42 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails_app/config/locales/en.yml +10 -0
- data/test/rails_app/config/routes.rb +3 -0
- data/test/rails_app/db/migrate/20110928102949_create_tables.rb +25 -0
- data/test/rails_app/db/schema.rb +20 -0
- data/test/rails_app/lib/assets/.gitkeep +0 -0
- data/test/rails_app/lib/tasks/.gitkeep +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/public/index.html +241 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/rails_app/script/rails +6 -0
- metadata +232 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'test/unit'
|
13
|
+
require 'ruby-debug'
|
14
|
+
require 'shoulda'
|
15
|
+
require 'stepper'
|
16
|
+
require "rails_app/config/environment"
|
17
|
+
require "rails/test_help"
|
18
|
+
require 'capybara/rails'
|
19
|
+
|
20
|
+
ActiveRecord::Migrator.migrate(File.expand_path("../rails_app/db/migrate/", __FILE__))
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class StepperButtonsTest < ActionController::IntegrationTest
|
4
|
+
test "first step should have 'finish later' and 'next step' buttons" do
|
5
|
+
get new_company_path
|
6
|
+
assert_select "li.next_step" do
|
7
|
+
assert_select "input[value='Next step']"
|
8
|
+
end
|
9
|
+
assert_select "li.save" do
|
10
|
+
assert_select "input[value='Finish later']"
|
11
|
+
end
|
12
|
+
assert_select "li.previous_step", false, "This page must contain no previous button"
|
13
|
+
end
|
14
|
+
|
15
|
+
test "second step should have 'finish later', 'previous step' and 'next step' buttons" do
|
16
|
+
company = Company.create!(:name => "My company", :my_step => "step1")
|
17
|
+
get new_company_path(:id => company.id)
|
18
|
+
|
19
|
+
assert_select "li.next_step" do
|
20
|
+
assert_select "input[value='Next step']"
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_select "li.save" do
|
24
|
+
assert_select "input[value='Finish later']"
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_select "li.previous_step" do
|
28
|
+
assert_select "input[value='Previous step']"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test "last step should have 'finish later', 'previous step' and 'finish' buttons" do
|
33
|
+
company = Company.create!(:name => "My company", :code => "04108", :my_step => "step2")
|
34
|
+
get new_company_path(:id => company.id)
|
35
|
+
|
36
|
+
assert_select "li.finish" do
|
37
|
+
assert_select "input[value='Finish form']"
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_select "li.save" do
|
41
|
+
assert_select "input[value='Finish later']"
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_select "li.previous_step" do
|
45
|
+
assert_select "input[value='Previous step']"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class StepsTest < ActionController::IntegrationTest
|
4
|
+
include Capybara::DSL
|
5
|
+
|
6
|
+
test "fill all steps" do
|
7
|
+
visit new_company_path
|
8
|
+
fill_in "Name", :with => "My company"
|
9
|
+
click_button "Next step"
|
10
|
+
fill_in "Code", :with => "04108"
|
11
|
+
click_button "Next step"
|
12
|
+
fill_in "City", :with => "Kiev"
|
13
|
+
click_button "Finish form"
|
14
|
+
assert_equal page.current_path, company_path(Company.last)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
test "previous step" do
|
19
|
+
visit new_company_path
|
20
|
+
fill_in "Name", :with => "My company"
|
21
|
+
click_button "Next step"
|
22
|
+
assert page.has_selector?('label', :text => 'Code')
|
23
|
+
click_button "Previous step"
|
24
|
+
assert page.has_selector?('label', :text => 'Name')
|
25
|
+
assert page.has_selector?('#company_name', :value => 'My company')
|
26
|
+
assert page.has_no_selector?('#error_explanation')
|
27
|
+
end
|
28
|
+
|
29
|
+
test "finish later" do
|
30
|
+
visit new_company_path
|
31
|
+
fill_in "Name", :with => "My company"
|
32
|
+
click_button "Next step"
|
33
|
+
assert page.has_selector?('label', :text => 'Code')
|
34
|
+
click_button "Finish later"
|
35
|
+
assert_equal page.current_path, companies_path
|
36
|
+
assert page.has_no_selector?('#error_explanation')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class AssignsModelTest < ActiveSupport::TestCase
|
3
|
+
|
4
|
+
test "should assign default column" do
|
5
|
+
assert_equal User._stepper_current_step_column, :current_step
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should assign column from options" do
|
9
|
+
assert_equal Company._stepper_current_step_column, :my_step
|
10
|
+
end
|
11
|
+
|
12
|
+
test "should assign default steps" do
|
13
|
+
assert_equal Company._stepper_steps, ["step1", "step2", "step3"]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class InstanceModelTest < ActiveSupport::TestCase
|
3
|
+
setup do
|
4
|
+
@company = Company.new
|
5
|
+
end
|
6
|
+
|
7
|
+
test "should have steeper_steps methods" do
|
8
|
+
assert_equal @company.stepper_steps, ["step1", "step2", "step3"]
|
9
|
+
end
|
10
|
+
|
11
|
+
test "should have steps methods if steps method is free" do
|
12
|
+
assert_equal @company.steps, ["step1", "step2", "step3"]
|
13
|
+
end
|
14
|
+
|
15
|
+
test "should check step is first" do
|
16
|
+
assert @company.first_step?("step1")
|
17
|
+
assert !@company.first_step?("step3")
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should check step is last" do
|
21
|
+
assert @company.last_step?("step3")
|
22
|
+
assert !@company.last_step?("step1")
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should check current step is first" do
|
26
|
+
@company.my_step = "step1"
|
27
|
+
assert @company.first_step?
|
28
|
+
@company.my_step = "step3"
|
29
|
+
assert !@company.first_step?
|
30
|
+
end
|
31
|
+
|
32
|
+
test "should check current step is last" do
|
33
|
+
@company.my_step = "step3"
|
34
|
+
assert @company.last_step?
|
35
|
+
@company.my_step = "step1"
|
36
|
+
assert !@company.last_step?
|
37
|
+
end
|
38
|
+
|
39
|
+
test "should return previous step" do
|
40
|
+
assert_equal @company.previous_step, nil
|
41
|
+
@company.my_step = "step1"
|
42
|
+
assert_equal @company.previous_step, nil
|
43
|
+
@company.my_step = "step2"
|
44
|
+
assert_equal @company.previous_step, "step1"
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should return next step" do
|
48
|
+
assert_equal @company.next_step, "step1"
|
49
|
+
@company.my_step = "step2"
|
50
|
+
assert_equal @company.next_step, "step3"
|
51
|
+
@company.my_step = "step3"
|
52
|
+
assert_equal @company.next_step, nil
|
53
|
+
end
|
54
|
+
|
55
|
+
test "should next_step! change step" do
|
56
|
+
@company.next_step!
|
57
|
+
assert_equal @company.my_step, "step1"
|
58
|
+
end
|
59
|
+
|
60
|
+
test "should previous_step! change step" do
|
61
|
+
@company.my_step = "step3"
|
62
|
+
@company.previous_step!
|
63
|
+
assert_equal @company.my_step, "step2"
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class ActiveRecordTest < ActiveSupport::TestCase
|
3
|
+
|
4
|
+
test "should have method" do
|
5
|
+
assert_respond_to ActiveRecord::Base, :has_steps
|
6
|
+
end
|
7
|
+
|
8
|
+
test "should raise exception if options isn't hash" do
|
9
|
+
assert_raise Stepper::StepperException do
|
10
|
+
ActiveRecord::Base.has_steps "something"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
test "should raise exception if options is wrong" do
|
15
|
+
assert_raise Stepper::StepperException do
|
16
|
+
ActiveRecord::Base.has_steps :some => "some", :steps => ["step1", "step2"]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should raise exception if options haven't :steps" do
|
21
|
+
assert_raise Stepper::StepperException do
|
22
|
+
ActiveRecord::Base.has_steps
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class ValidationModelTest < ActiveSupport::TestCase
|
3
|
+
setup do
|
4
|
+
@company = Company.new
|
5
|
+
end
|
6
|
+
|
7
|
+
test "should validate step1" do
|
8
|
+
@company.my_step = "step1"
|
9
|
+
assert !@company.save
|
10
|
+
assert_equal @company.errors.messages, { :name=>["can't be blank"] }
|
11
|
+
end
|
12
|
+
|
13
|
+
should "validate step 3 and previous steps" do
|
14
|
+
@company.my_step = "step3"
|
15
|
+
assert !@company.save
|
16
|
+
assert_equal @company.errors.messages, { :name => ["can't be blank"],
|
17
|
+
:code => ["is not a number"],
|
18
|
+
:city => ["can't be blank"] }
|
19
|
+
end
|
20
|
+
|
21
|
+
should "not run method if it doesn't exists" do
|
22
|
+
class << @company
|
23
|
+
undef_method :validate_step2
|
24
|
+
end
|
25
|
+
|
26
|
+
@company.name = "name"
|
27
|
+
@company.city = "Kiev"
|
28
|
+
@company.my_step = "step3"
|
29
|
+
|
30
|
+
assert_nothing_raised NoMethodError do
|
31
|
+
@company.save!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
RailsApp::Application.load_tasks
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Company < ActiveRecord::Base
|
2
|
+
has_steps :current_step_column => :my_step, :steps => ["step1", "step2", "step3"]
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def validate_step1
|
7
|
+
self.validates_presence_of :name
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate_step2
|
11
|
+
self.validates_numericality_of :code
|
12
|
+
end
|
13
|
+
|
14
|
+
def validate_step3
|
15
|
+
self.validates_presence_of :city
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
index page
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<% if @company.errors.any? %>
|
2
|
+
<div id="error_explanation">
|
3
|
+
<h2><%= pluralize(@company.errors.count, "error") %> prohibited this company from being saved:</h2>
|
4
|
+
|
5
|
+
<ul>
|
6
|
+
<% @company.errors.full_messages.each do |msg| %>
|
7
|
+
<li><%= msg %></li>
|
8
|
+
<% end %>
|
9
|
+
</ul>
|
10
|
+
</div>
|
11
|
+
<% end %>
|
12
|
+
<%= form_for @company do |f|%>
|
13
|
+
<%= stepper f %>
|
14
|
+
<% end %>
|
@@ -0,0 +1 @@
|
|
1
|
+
show page
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "active_resource/railtie"
|
8
|
+
require "rails/test_unit/railtie"
|
9
|
+
|
10
|
+
require "stepper"
|
11
|
+
|
12
|
+
module RailsApp
|
13
|
+
class Application < Rails::Application
|
14
|
+
# Settings in config/environments/* take precedence over those specified here.
|
15
|
+
# Application configuration should go into files in config/initializers
|
16
|
+
# -- all .rb files in that directory are automatically loaded.
|
17
|
+
|
18
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
19
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
20
|
+
|
21
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
22
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
23
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
24
|
+
|
25
|
+
# Activate observers that should always be running.
|
26
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
27
|
+
|
28
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
29
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
30
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
31
|
+
|
32
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
33
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
34
|
+
# config.i18n.default_locale = :de
|
35
|
+
|
36
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
37
|
+
config.encoding = "utf-8"
|
38
|
+
|
39
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
40
|
+
config.filter_parameters += [:password]
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|