wizardz 1.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/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +47 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/wizardz.rb +4 -0
- data/lib/wizardz/page.rb +75 -0
- data/lib/wizardz/page/first.rb +8 -0
- data/lib/wizardz/wizard.rb +87 -0
- data/lib/wizardz/wizard_object.rb +11 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/wizardz/page_spec.rb +100 -0
- data/spec/wizardz/wizard_spec.rb +168 -0
- data/spec/wizardz_spec.rb +7 -0
- data/test/helper.rb +10 -0
- data/test/test_wizardz.rb +7 -0
- data/wizardz.gemspec +67 -0
- metadata +106 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Henry
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= wizardz
|
2
|
+
|
3
|
+
Multi-Step Creation Wizard
|
4
|
+
|
5
|
+
Design to provide a framework for creating multi-step wizard which can have multiple
|
6
|
+
models and user-selectable steps ordering based on user input within earlier steps.
|
7
|
+
|
8
|
+
The Gem is provides a Wizardz::Wizard class which is exposed to the Controller and
|
9
|
+
manages the various steps within the creation process and a Wizardz::Page class
|
10
|
+
with represents the individendual pages within the Wizardz. Both class are designed
|
11
|
+
to be inherited from within the final implementation and expose the following methods:
|
12
|
+
|
13
|
+
Wizardz::Wizard
|
14
|
+
---------------
|
15
|
+
STATES => Constant which contains the HASH of Page Identifier and Page Class pairs
|
16
|
+
def create => Combines the data for the Associated Pages and create the required Objects
|
17
|
+
|
18
|
+
Wizardz::Page
|
19
|
+
---------------
|
20
|
+
IDENTIFER => Identifier lookup which should match to the Page
|
21
|
+
Identifier from The Wizardz::Wizard:STATES Constant
|
22
|
+
PARTIAL => Contant name of the Partial to be displayed within
|
23
|
+
the view for the page
|
24
|
+
def initialize(data) => Load the required Attributes onto the Page Class
|
25
|
+
(set any default values here)
|
26
|
+
def get_valid_states(states) => Update the list page transistion order after page data update
|
27
|
+
def get_object => Return instance of the underlying object (in memory
|
28
|
+
only - do not save to table) (only required if
|
29
|
+
page_object and valid NOT overwritten
|
30
|
+
def page_object => return object instance (with valid? call if page
|
31
|
+
has already been visited)
|
32
|
+
def valid? => return true/false if object is valid (default
|
33
|
+
implementation calls valid? on get_object)
|
34
|
+
|
35
|
+
== Note on Patches/Pull Requests
|
36
|
+
|
37
|
+
* Fork the project.
|
38
|
+
* Make your feature addition or bug fix.
|
39
|
+
* Add tests for it. This is important so I don't break it in a
|
40
|
+
future version unintentionally.
|
41
|
+
* Commit, do not mess with rakefile, version, or history.
|
42
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
43
|
+
* Send me a pull request. Bonus points for topic branches.
|
44
|
+
|
45
|
+
== Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2010 David Henry. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "wizardz"
|
8
|
+
gem.summary = %Q{Multi-Step Wizard}
|
9
|
+
gem.description = %Q{Multi-Step wizard that deals with multiple models and changing step options based on previous step input}
|
10
|
+
gem.email = "dave_henry@lyagushka.co.uk"
|
11
|
+
gem.homepage = "http://github.com/dwhenry/wizardz"
|
12
|
+
gem.authors = ["David Henry"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "wizardz #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/lib/wizardz.rb
ADDED
data/lib/wizardz/page.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#require File.dirname(__FILE__) + '/page/fund_general'
|
2
|
+
|
3
|
+
module Wizardz
|
4
|
+
class Page
|
5
|
+
attr_reader :page_data
|
6
|
+
attr_accessor :wizard_inst
|
7
|
+
|
8
|
+
def self.load_pages(states, page_data, wizard_inst)
|
9
|
+
return_val = {}
|
10
|
+
wizard_inst.classes.each do |class_obj|
|
11
|
+
return_val.merge!(self.subclass_element(class_obj,page_data, states, wizard_inst))
|
12
|
+
end
|
13
|
+
return_val
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.subclass_element(class_obj, page_data,states,wizard_inst)
|
17
|
+
id = class_obj::IDENTIFIER rescue nil
|
18
|
+
return {} if id.nil? or !states.include?(id)
|
19
|
+
|
20
|
+
obj = class_obj.new(page_data[id] || {})
|
21
|
+
obj.wizard_inst = wizard_inst
|
22
|
+
{id => obj}
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def valid?(allow_nil=true)
|
27
|
+
return allow_nil if @page_data.nil?
|
28
|
+
self.get_object.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
def page_object
|
32
|
+
obj = self.get_object
|
33
|
+
obj.valid? unless @wizard_inst.unprocessed.include?(self.identifier)
|
34
|
+
obj
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_valid_states(states)
|
38
|
+
states
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(data={})
|
42
|
+
@page_data = data || {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def partial
|
46
|
+
self.class::PARTIAL rescue "#{self.identifier.to_s}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def page_data
|
50
|
+
@page_data
|
51
|
+
end
|
52
|
+
|
53
|
+
def update(data)
|
54
|
+
@page_data = data[:dataset]
|
55
|
+
self.valid?(false)
|
56
|
+
end
|
57
|
+
|
58
|
+
def transit(direction, states)
|
59
|
+
pos = states.index(self.identifier)
|
60
|
+
raise 'Invalid States list' if pos.nil?
|
61
|
+
pos += 1 if direction == 'next' and pos < states.size - 1
|
62
|
+
pos -= 1 if direction == 'prev' and pos > 0
|
63
|
+
states[pos]
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
def identifier
|
68
|
+
self.class::IDENTIFIER rescue nil
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_object
|
72
|
+
WizardObject.new(@page_data)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'wizardz/page'
|
2
|
+
require 'wizardz/page/first'
|
3
|
+
require 'wizardz/wizard_object'
|
4
|
+
|
5
|
+
module Wizardz
|
6
|
+
class Wizard
|
7
|
+
attr_reader :pages
|
8
|
+
attr_reader :state
|
9
|
+
attr_reader :valid_states
|
10
|
+
attr_reader :unprocessed
|
11
|
+
|
12
|
+
STATES={:first_state => Wizardz::Page::First}
|
13
|
+
|
14
|
+
def initialize(fund_data={},state=nil)
|
15
|
+
state = self.states.first if state.nil?
|
16
|
+
state = state.to_sym
|
17
|
+
raise "Invalid State Assignment: #{state}" unless self.states.include?(state)
|
18
|
+
self.load_data(fund_data)
|
19
|
+
@state = state
|
20
|
+
end
|
21
|
+
|
22
|
+
def first_page?
|
23
|
+
self.states.index(@state) <= 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def last_page?
|
27
|
+
self.states.index(@state) >= (self.states.size - 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
def states
|
31
|
+
self.class::STATES.keys
|
32
|
+
end
|
33
|
+
|
34
|
+
def classes
|
35
|
+
self.class::STATES.values
|
36
|
+
end
|
37
|
+
|
38
|
+
def create
|
39
|
+
raise "Create method must be implemented in subclass"
|
40
|
+
end
|
41
|
+
|
42
|
+
def update(data, direction=:next)
|
43
|
+
return true if data.nil?
|
44
|
+
if @pages[@state].update(data)
|
45
|
+
@valid_states = @pages[@state].get_valid_states(@valid_states)
|
46
|
+
@state = @pages[@state].transit(direction, @valid_states)
|
47
|
+
else
|
48
|
+
@state = @pages[@state].transit(direction, @valid_states) if direction.to_sym == :prev
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
return true
|
52
|
+
end
|
53
|
+
|
54
|
+
protected
|
55
|
+
def load_data(fund_data)
|
56
|
+
@valid_states = fund_data[:valid_states] || self.states
|
57
|
+
@unprocessed = fund_data[:unprocessed] || self.states
|
58
|
+
@state ||= self.states.first
|
59
|
+
@pages = Page.load_pages(self.states, fund_data, self)
|
60
|
+
end
|
61
|
+
|
62
|
+
public
|
63
|
+
def save_data
|
64
|
+
results = {}
|
65
|
+
@valid_states.each do |state|
|
66
|
+
results[state] = @pages[state].page_data if @pages[state].respond_to?(:page_data)
|
67
|
+
end
|
68
|
+
results[:states] = @valid_states
|
69
|
+
results[:unprocessed] = @unprocessed.clone
|
70
|
+
results[:unprocessed].delete(@state)
|
71
|
+
results
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_page
|
75
|
+
@pages[@state].page_data
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_page_object
|
79
|
+
@pages[@state].page_object
|
80
|
+
end
|
81
|
+
|
82
|
+
def partial
|
83
|
+
@pages[@state].partial
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
class TestClass1 < Wizardz::Page
|
5
|
+
end
|
6
|
+
class TestClass2 < Wizardz::Page
|
7
|
+
IDENTIFIER = :test_class
|
8
|
+
end
|
9
|
+
class TestClass3 < Wizardz::Page
|
10
|
+
IDENTIFIER = :test_class
|
11
|
+
def valid?(allow_nil=true); end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "Page" do
|
15
|
+
|
16
|
+
it "calls new for each subclass" do
|
17
|
+
page_data = {:first_state => {:value => 'test'}}
|
18
|
+
page = Wizardz::Page::First.new
|
19
|
+
Wizardz::Page::First.should_receive(:new).with({:value => 'test'}).and_return(page)
|
20
|
+
Wizardz::Page.load_pages([:first_state], page_data, mock(Wizardz::Wizard, :classes => [Wizardz::Page::First]))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "does not call subclass that do not respond to IDENTIFIER" do
|
24
|
+
wiz_inst = Wizardz::Wizard.new()
|
25
|
+
TestClass1.should_not_receive(:new).with(anything)
|
26
|
+
Wizardz::Page.load_pages([], {}, wiz_inst)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not call subclass that do not exist in states array" do
|
30
|
+
wiz_inst = Wizardz::Wizard.new()
|
31
|
+
TestClass1.should_not_receive(:new).with(anything)
|
32
|
+
Wizardz::Page::First.should_not_receive(:new).with(anything)
|
33
|
+
Wizardz::Page.load_pages([],{}, wiz_inst)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "does not modify input/output data on get_valid_states call by default" do
|
37
|
+
page = Wizardz::Page::First.new({})
|
38
|
+
page.get_valid_states([:first_state, :second_state]).should == [:first_state, :second_state]
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not raise an error if no initialize method is implemented' do
|
42
|
+
lambda {TestClass2.new({})}.should_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns the page_data object" do
|
46
|
+
page = Wizardz::Page::First.new({:value => 'test'})
|
47
|
+
page.page_data.should == {:value => 'test'}
|
48
|
+
end
|
49
|
+
context 'update' do
|
50
|
+
it "does not raise an error if no update method implemented" do
|
51
|
+
page = TestClass3.new({})
|
52
|
+
lambda {page.update({:value => 'test 2'})}.should_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'calls the valid? method during the update' do
|
56
|
+
page = Wizardz::Page::First.new({})
|
57
|
+
page.should_receive(:valid?).with(false)
|
58
|
+
page.update({:value => 'test 2'})
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'updates the page data element based on :dataset key from data' do
|
62
|
+
page = Wizardz::Page::First.new({})
|
63
|
+
page.update({:dataset => {:value => 'test 2'}})
|
64
|
+
page.page_data.should == {:value => 'test 2'}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'transit wizard states' do
|
69
|
+
it 'not raise an error if transit if not implemented' do
|
70
|
+
page = Wizardz::Page::First.new({})
|
71
|
+
lambda{page.transit('prev',[:first_state])}.should_not raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'stay on the same state if next and last state' do
|
75
|
+
page = Wizardz::Page::First.new({})
|
76
|
+
page.transit('next',[:second_state, :first_state]).should == :first_state
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'moves to the next state if next and not last state' do
|
80
|
+
page = Wizardz::Page::First.new({})
|
81
|
+
page.transit('next',[:first_state, :second_state]).should == :second_state
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'stay on the same state if prev and first state' do
|
85
|
+
page = Wizardz::Page::First.new({})
|
86
|
+
page.transit('prev',[:first_state, :second_state]).should == :first_state
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'moves to the next state if prev and not first state' do
|
90
|
+
page = Wizardz::Page::First.new({})
|
91
|
+
page.transit('prev',[:second_state, :first_state]).should == :second_state
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'raise an error if current state if not in options' do
|
95
|
+
page = Wizardz::Page::First.new({})
|
96
|
+
lambda{page.transit('prev',[:second_state])}.should raise_error
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
class TestClassWiz < Wizardz::Page
|
4
|
+
IDENTIFIER = :test_class_wiz
|
5
|
+
def page_object
|
6
|
+
[Wizardz::WizardObject.new('aaa'), Wizardz::WizardObject.new('nnn')]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class StateRedefWiz < Wizardz::Wizard
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "Wizard" do
|
14
|
+
|
15
|
+
it "has minimum of 0 parameters on creation" do
|
16
|
+
lambda{Wizardz::Wizard.new()}.should_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a two optional parameters" do
|
20
|
+
lambda{Wizardz::Wizard.new({}, :first_state)}.should_not raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
it "2nd paramter must be a member of 'states'" do
|
24
|
+
lambda{Wizardz::Wizard.new({}, :invalid_state)}.should raise_error
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'initialises valid states from params' do
|
28
|
+
wiz = Wizardz::Wizard.new({:valid_states => [:first_state, :second_state]})
|
29
|
+
wiz.valid_states.should == [:first_state, :second_state]
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'initialises valid states to default value' do
|
33
|
+
StateRedefWiz.class_eval("def states; return [:first_state];end")
|
34
|
+
wiz = StateRedefWiz.new()
|
35
|
+
wiz.valid_states.should == [:first_state]
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'initialises unprocessed states from params' do
|
39
|
+
wiz = Wizardz::Wizard.new({:unprocessed => [:first_state, :second_state]})
|
40
|
+
wiz.unprocessed.should == [:first_state, :second_state]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'initialises unprocessed states to default value' do
|
44
|
+
StateRedefWiz.class_eval("def states; return [:first_state];end")
|
45
|
+
wiz = Wizardz::Wizard.new()
|
46
|
+
wiz.unprocessed.should == [:first_state]
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'initialises current state from params' do
|
50
|
+
#TODO:: could this be a stub??
|
51
|
+
StateRedefWiz.class_eval('def states; return [:first_state,:second_state]; end')
|
52
|
+
wiz = StateRedefWiz.new({}, :second_state)
|
53
|
+
wiz.state.should == :second_state
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'initialises current_state states to default value' do
|
57
|
+
wiz = StateRedefWiz.new()
|
58
|
+
wiz.state.should == :first_state
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'initialises the fund_page objects from params' do
|
62
|
+
setup_data = {:first_state => {:value => 'test'}}
|
63
|
+
Wizardz::Page.should_receive(:load_pages).with([:first_state, :second_state], setup_data,anything)
|
64
|
+
wiz = StateRedefWiz.new(setup_data)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'initialises the fund_page to default value' do
|
68
|
+
Wizardz::Page.should_receive(:load_pages).with([:first_state, :second_state],{},anything)
|
69
|
+
wiz = StateRedefWiz.new()
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the data_object to save from default values' do
|
73
|
+
wiz = StateRedefWiz.new()
|
74
|
+
wiz.save_data.should == {:first_state=>{},
|
75
|
+
:unprocessed=>[:second_state],
|
76
|
+
:states=>[:first_state, :second_state]}
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns the data_object to save from default values' do
|
80
|
+
wiz = StateRedefWiz.new({:first_state => {:value => 'test'}})
|
81
|
+
wiz.save_data.should == {:first_state=>{:value=>"test"},
|
82
|
+
:unprocessed=>[:second_state],
|
83
|
+
:states=>[:first_state, :second_state]}
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns the view partial for the wizard' do
|
87
|
+
wiz = StateRedefWiz.new({:first_state => {:value => 'test'}})
|
88
|
+
wiz.partial.should == 'first_state'
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns the current page data' do
|
92
|
+
wiz = StateRedefWiz.new({:first_state => {:value => 'test'}})
|
93
|
+
wiz.pages.inspect
|
94
|
+
wiz.get_page.should == {:value => 'test'}
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the current page data object' do
|
98
|
+
wiz = StateRedefWiz.new({:first_state => {:value => 'test'}})
|
99
|
+
obj = wiz.get_page_object
|
100
|
+
obj.is_a?(Wizardz::WizardObject).should be_true
|
101
|
+
obj.page_data.should == {:value => 'test'}
|
102
|
+
end
|
103
|
+
|
104
|
+
context 'return an array from page object' do
|
105
|
+
before(:each) do
|
106
|
+
StateRedefWiz.class_eval("def states; return [:first_state,:test_class_wiz];end")
|
107
|
+
StateRedefWiz.class_eval("def classes; return [Wizardz::Page::First,TestClassWiz];end")
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'returns an Array object when page object evals to an array' do
|
111
|
+
wiz = StateRedefWiz.new({:valid_states => [:test_class_wiz],:unprocessed => [:test_class_wiz]}, :test_class_wiz)
|
112
|
+
wiz.get_page_object.is_a?(Array).should be_true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'does not raise an error with page object an array and unprocessed' do
|
116
|
+
wiz = StateRedefWiz.new({:valid_states => [:test_class_wiz],:unprocessed => [:test_class_wiz]}, :test_class_wiz)
|
117
|
+
lambda{wiz.get_page_object}.should_not raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'does not raise an error with page object an array and not unprocessed' do
|
121
|
+
wiz = StateRedefWiz.new({:valid_states => [:test_class_wiz],:unprocessed => []}, :test_class_wiz)
|
122
|
+
lambda{wiz.get_page_object}.should_not raise_error
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'update function' do
|
127
|
+
it 'does not call the update code if a the data passed in is nil' do
|
128
|
+
wiz = StateRedefWiz.new
|
129
|
+
page = wiz.pages[wiz.state]
|
130
|
+
page.should_not_receive(:update)
|
131
|
+
wiz.update(nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'calls the update code if a the data passed in is not nil' do
|
135
|
+
wiz = StateRedefWiz.new
|
136
|
+
page = wiz.pages[wiz.state]
|
137
|
+
page.should_receive(:update).and_return(false)
|
138
|
+
wiz.update(1)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'calls get_valid_states and transit if update is true' do
|
142
|
+
wiz = StateRedefWiz.new
|
143
|
+
page = wiz.pages[wiz.state]
|
144
|
+
page.stub!(:update).and_return(true)
|
145
|
+
page.should_receive(:get_valid_states).and_return([])
|
146
|
+
page.should_receive(:transit).and_return(:first_state)
|
147
|
+
wiz.update(1)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'does not calls get_valid_states or transit if update is false' do
|
151
|
+
wiz = StateRedefWiz.new
|
152
|
+
page = wiz.pages[wiz.state]
|
153
|
+
page.stub!(:update).and_return(false)
|
154
|
+
page.should_not_receive(:get_valid_states)
|
155
|
+
page.should_not_receive(:transit)
|
156
|
+
wiz.update(1)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
# it 'return true for the first_look? value (indicates if page should be validated)' do
|
160
|
+
# wiz = Wizardz::Wizard.new({:unprocessed => [:first_state]})
|
161
|
+
# wiz.first_look?.should be_true
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# it 'return false for the first_look? value (indicates if page should be validated)' do
|
165
|
+
# wiz = Wizardz::Wizard.new({:unprocessed => []})
|
166
|
+
# wiz.first_look?.should be_false
|
167
|
+
# end
|
168
|
+
end
|
data/test/helper.rb
ADDED
data/wizardz.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{wizardz}
|
8
|
+
s.version = "1.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Henry"]
|
12
|
+
s.date = %q{2010-06-08}
|
13
|
+
s.description = %q{Multi-Step wizard that deals with multiple models and changing step options based on previous step input}
|
14
|
+
s.email = %q{dave_henry@lyagushka.co.uk}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/wizardz.rb",
|
27
|
+
"lib/wizardz/page.rb",
|
28
|
+
"lib/wizardz/page/first.rb",
|
29
|
+
"lib/wizardz/wizard.rb",
|
30
|
+
"lib/wizardz/wizard_object.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb",
|
33
|
+
"spec/wizardz/page_spec.rb",
|
34
|
+
"spec/wizardz/wizard_spec.rb",
|
35
|
+
"spec/wizardz_spec.rb",
|
36
|
+
"test/helper.rb",
|
37
|
+
"test/test_wizardz.rb",
|
38
|
+
"wizardz.gemspec"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/dwhenry/wizardz}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
44
|
+
s.summary = %q{Multi-Step Wizard}
|
45
|
+
s.test_files = [
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/wizardz/page_spec.rb",
|
48
|
+
"spec/wizardz/wizard_spec.rb",
|
49
|
+
"spec/wizardz_spec.rb",
|
50
|
+
"test/helper.rb",
|
51
|
+
"test/test_wizardz.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wizardz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Henry
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-08 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Multi-Step wizard that deals with multiple models and changing step options based on previous step input
|
38
|
+
email: dave_henry@lyagushka.co.uk
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- LICENSE
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- VERSION
|
53
|
+
- lib/wizardz.rb
|
54
|
+
- lib/wizardz/page.rb
|
55
|
+
- lib/wizardz/page/first.rb
|
56
|
+
- lib/wizardz/wizard.rb
|
57
|
+
- lib/wizardz/wizard_object.rb
|
58
|
+
- spec/spec.opts
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
- spec/wizardz/page_spec.rb
|
61
|
+
- spec/wizardz/wizard_spec.rb
|
62
|
+
- spec/wizardz_spec.rb
|
63
|
+
- test/helper.rb
|
64
|
+
- test/test_wizardz.rb
|
65
|
+
- wizardz.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/dwhenry/wizardz
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Multi-Step Wizard
|
100
|
+
test_files:
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- spec/wizardz/page_spec.rb
|
103
|
+
- spec/wizardz/wizard_spec.rb
|
104
|
+
- spec/wizardz_spec.rb
|
105
|
+
- test/helper.rb
|
106
|
+
- test/test_wizardz.rb
|