incredible 0.0.3.pre → 0.0.4.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41debf17d70ff5ec110c18adc7e772b56ff48328
4
- data.tar.gz: 1fa531e0c3b0f7d029918061a96adf8b2fc66752
3
+ metadata.gz: a9967783a3c29d3e6e0c2dc35620a1b2e701c641
4
+ data.tar.gz: d256c193fee0f8890f4249c569c80fc53e6542e3
5
5
  SHA512:
6
- metadata.gz: 95753133501fc2424219e7572c9057b0a188d8e1c4da39a69a057c082bce423d1c6b71ecb12b5b7978f26029babb0bc4f1aae7a49101ebdf0930eeac9515298e
7
- data.tar.gz: 9e59d02f74d5516d8ae4f6932c8443e3a3d6973e28b6175643a6f283a5401855581be02da12d646b0a92e5a71235f0abd11dec0ec76c4065df2f130632323ddf
6
+ metadata.gz: 9f49b649c899ec64a7f315b8bfa7fc5669a990b7603eedfa5fca255f78a80cb9fbf26770210602c60ee83c750b492f2835888ac19f32aba1b3216a23f14ab90f
7
+ data.tar.gz: eb69d551623f687e35e9a98bc4dc5ae4797bf77b5aec0cd70b3f1d45f947380942a203e59715d5e54a6a126bdba22c9abd8eabfb59cf78c5c5ef2055efcfa322
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ rescue LoadError
5
5
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
6
  end
7
7
 
8
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
8
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
9
9
  load 'rails/tasks/engine.rake'
10
10
 
11
11
  Bundler::GemHelper.install_tasks
data/lib/incredible.rb CHANGED
@@ -4,6 +4,7 @@ require 'incredible/engine'
4
4
  require 'incredible/loader'
5
5
  require 'incredible/form'
6
6
  require 'incredible/step'
7
+ require 'incredible/rule'
7
8
 
8
9
  require 'incredible/wizard'
9
10
 
@@ -0,0 +1,15 @@
1
+ module Incredible
2
+ class Rule
3
+ attr_accessor :next_params
4
+ attr_accessor :next_step
5
+ attr_reader :params
6
+
7
+ def initialize(params)
8
+ @params = params
9
+ process
10
+ end
11
+
12
+ def process; end
13
+
14
+ end
15
+ end
@@ -5,7 +5,7 @@ module Incredible
5
5
  @name = name.to_s
6
6
  @data = data.symbolize_keys
7
7
 
8
- %I[questions template].each do |k|
8
+ %I[questions template next_step].each do |k|
9
9
  self.class.send :define_method, k.to_sym do
10
10
  @data[k]
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Incredible
2
- VERSION = '0.0.3.pre'.freeze
2
+ VERSION = '0.0.4.pre'.freeze
3
3
  end
@@ -7,7 +7,7 @@ module Incredible
7
7
 
8
8
  included do
9
9
  before_action :load_step, only: %i[show update]
10
- before_action :process_rules, only: :update
10
+ before_action :load_next_step, only: :update
11
11
  before_action :load_step_data, only: %i[show update]
12
12
  end
13
13
 
@@ -20,10 +20,13 @@ module Incredible
20
20
  self.questions = step_data.questions
21
21
  end
22
22
 
23
- def process_rules
24
- return unless step_data.rule
25
- next_step = step_data.rule.send(:process, params)
26
- jump_to next_step
23
+ def load_next_step
24
+ if step_data.rule
25
+ @rule = step_data.rule.send(:new, params)
26
+ jump_to @rule.next_step
27
+ elsif step_data.next_step
28
+ jump_to step_data.next_step
29
+ end
27
30
  end
28
31
 
29
32
  module ClassMethods
@@ -20,7 +20,7 @@ describe FormsController, type: :controller do
20
20
  it 'follows a rule' do
21
21
  expect(
22
22
  (put :update, params: { id: :step1, model: { name: 'Mike' } })
23
- ).to redirect_to('http://test.host/forms/step3')
23
+ ).to redirect_to('http://test.host/forms/step3?foo=bar')
24
24
  end
25
25
 
26
26
  it 'goes to the next step by default' do
@@ -30,4 +30,19 @@ describe FormsController, type: :controller do
30
30
  end
31
31
  end
32
32
 
33
+ context 'next step is specified' do
34
+ it 'goes to that step' do
35
+ expect(
36
+ (put :update, params: {
37
+ id: :step2,
38
+ model: {
39
+ email: 'me@example.org',
40
+ phone_number: '323232'
41
+ }
42
+ }
43
+ )
44
+ ).to redirect_to('http://test.host/forms/step4')
45
+ end
46
+ end
47
+
33
48
  end
@@ -9,7 +9,7 @@ class FormsController < ActionController::Base
9
9
 
10
10
  def update
11
11
  @model = StubModel.new(permitted_params)
12
- render_wizard @model
12
+ render_wizard @model, {}, (@rule&.next_params || {})
13
13
  end
14
14
 
15
15
  private
@@ -17,5 +17,4 @@ class FormsController < ActionController::Base
17
17
  def permitted_params
18
18
  params.require(:model).permit(:name, :postcode, :email, :phone_number)
19
19
  end
20
-
21
20
  end
@@ -1,8 +1,9 @@
1
- class Step1Rule
1
+ class Step1Rule < Incredible::Rule
2
2
 
3
- def self.process(params)
3
+ def process
4
4
  return unless params[:model][:name] == 'Mike'
5
- :step3
5
+ @next_params = { foo: :bar }
6
+ @next_step = :step3
6
7
  end
7
8
 
8
9
  end
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
3
  load Gem.bin_path('bundler', 'bundle')
data/spec/dummy/bin/setup CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  include FileUtils
5
5
 
6
6
  # path to your application root.
7
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
7
+ APP_ROOT = Pathname.new File.expand_path('..', __dir__)
8
8
 
9
9
  def system!(*args)
10
10
  system(*args) || abort("\n== Command #{args} failed ==")
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  include FileUtils
5
5
 
6
6
  # path to your application root.
7
- APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
7
+ APP_ROOT = Pathname.new File.expand_path('..', __dir__)
8
8
 
9
9
  def system!(*args)
10
10
  system(*args) || abort("\n== Command #{args} failed ==")
data/spec/dummy/bin/yarn CHANGED
@@ -4,8 +4,8 @@ Dir.chdir(VENDOR_PATH) do
4
4
  begin
5
5
  exec "yarnpkg #{ARGV.join(' ')}"
6
6
  rescue Errno::ENOENT
7
- $stderr.puts 'Yarn executable was not detected in the system.'
8
- $stderr.puts 'Download Yarn at https://yarnpkg.com/en/docs/install'
7
+ warn 'Yarn executable was not detected in the system.'
8
+ warn 'Download Yarn at https://yarnpkg.com/en/docs/install'
9
9
  exit 1
10
10
  end
11
11
  end
@@ -15,6 +15,7 @@ form:
15
15
  widget: :input
16
16
  step2:
17
17
  template: bar
18
+ next_step: :step4
18
19
  questions:
19
20
  - name: :email
20
21
  title: Email
@@ -24,5 +25,7 @@ form:
24
25
  widget: :tel
25
26
  step3:
26
27
  template: :baz
28
+ step4:
29
+ template: :bar
27
30
 
28
31
 
data/spec/form_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Incredible::Form do
7
7
  describe '#step_names' do
8
8
 
9
9
  it 'returns step names' do
10
- expect(subject.step_names).to match_array(%w[step1 step2 step3])
10
+ expect(subject.step_names).to match_array(%w[step1 step2 step3 step4])
11
11
  end
12
12
 
13
13
  end
@@ -15,7 +15,7 @@ describe Incredible::Form do
15
15
  describe '#steps' do
16
16
 
17
17
  it 'returns the correct amount of steps' do
18
- expect(subject.steps.count).to eq(3)
18
+ expect(subject.steps.count).to eq(4)
19
19
  end
20
20
 
21
21
  it 'returns steps as Steps' do
data/spec/loader_spec.rb CHANGED
@@ -9,7 +9,7 @@ describe Incredible::Loader do
9
9
  it 'loads a form' do
10
10
  expect(form).to be_a(Hash)
11
11
  expect(form['form']['name']).to eq('Test form')
12
- expect(form['form']['steps'].keys).to eq(%w[step1 step2 step3])
12
+ expect(form['form']['steps'].keys).to eq(%w[step1 step2 step3 step4])
13
13
  end
14
14
 
15
15
  context 'with non-existent form' do
data/spec/spec_helper.rb CHANGED
@@ -3,7 +3,7 @@ Coveralls.wear_merged!
3
3
 
4
4
  ENV['RAILS_ENV'] ||= 'test'
5
5
 
6
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
6
+ require File.expand_path('dummy/config/environment.rb', __dir__)
7
7
  require 'rspec/rails'
8
8
  require 'rails-controller-testing'
9
9
  Rails::Controller::Testing.install
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incredible
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.pre
4
+ version: 0.0.4.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - pezholio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.3.2
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec-rails
42
+ name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
70
+ name: rails-controller-testing
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rails-controller-testing
98
+ name: rspec_junit_formatter
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rspec_junit_formatter
112
+ name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: coveralls
126
+ name: sqlite3
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -151,6 +151,7 @@ files:
151
151
  - lib/incredible/engine.rb
152
152
  - lib/incredible/form.rb
153
153
  - lib/incredible/loader.rb
154
+ - lib/incredible/rule.rb
154
155
  - lib/incredible/step.rb
155
156
  - lib/incredible/version.rb
156
157
  - lib/incredible/wizard.rb
@@ -225,49 +226,49 @@ signing_key:
225
226
  specification_version: 4
226
227
  summary: Build multi-page forms like a General
227
228
  test_files:
229
+ - spec/loader_spec.rb
230
+ - spec/controllers/forms_controller_spec.rb
228
231
  - spec/step_spec.rb
229
- - spec/dummy/config/environments/development.rb
230
- - spec/dummy/config/environments/test.rb
231
- - spec/dummy/config/environments/production.rb
232
- - spec/dummy/config/application.rb
232
+ - spec/dummy/bin/rake
233
+ - spec/dummy/bin/bundle
234
+ - spec/dummy/bin/setup
235
+ - spec/dummy/bin/rails
236
+ - spec/dummy/bin/yarn
237
+ - spec/dummy/bin/update
238
+ - spec/dummy/app/models/application_record.rb
239
+ - spec/dummy/app/models/stub_model.rb
240
+ - spec/dummy/app/controllers/forms_controller.rb
241
+ - spec/dummy/app/controllers/application_controller.rb
242
+ - spec/dummy/app/views/forms/bar.html.erb
243
+ - spec/dummy/app/views/forms/foo.html.erb
244
+ - spec/dummy/app/views/layouts/mailer.html.erb
245
+ - spec/dummy/app/views/layouts/mailer.text.erb
246
+ - spec/dummy/app/views/layouts/application.html.erb
247
+ - spec/dummy/app/rules/step1_rule.rb
248
+ - spec/dummy/config.ru
249
+ - spec/dummy/Rakefile
250
+ - spec/dummy/package.json
251
+ - spec/dummy/config/environment.rb
233
252
  - spec/dummy/config/secrets.yml
234
- - spec/dummy/config/spring.rb
235
- - spec/dummy/config/cable.yml
236
- - spec/dummy/config/forms/form.yml
237
- - spec/dummy/config/forms/bad-yaml.yml
238
- - spec/dummy/config/initializers/filter_parameter_logging.rb
253
+ - spec/dummy/config/initializers/inflections.rb
239
254
  - spec/dummy/config/initializers/wrap_parameters.rb
240
- - spec/dummy/config/initializers/mime_types.rb
241
- - spec/dummy/config/initializers/cookies_serializer.rb
242
- - spec/dummy/config/initializers/backtrace_silencers.rb
243
255
  - spec/dummy/config/initializers/application_controller_renderer.rb
244
256
  - spec/dummy/config/initializers/assets.rb
245
- - spec/dummy/config/initializers/inflections.rb
257
+ - spec/dummy/config/initializers/cookies_serializer.rb
258
+ - spec/dummy/config/initializers/backtrace_silencers.rb
259
+ - spec/dummy/config/initializers/mime_types.rb
260
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
246
261
  - spec/dummy/config/boot.rb
247
- - spec/dummy/config/environment.rb
248
- - spec/dummy/config/puma.rb
249
262
  - spec/dummy/config/routes.rb
263
+ - spec/dummy/config/forms/bad-yaml.yml
264
+ - spec/dummy/config/forms/form.yml
250
265
  - spec/dummy/config/locales/en.yml
251
- - spec/dummy/Rakefile
252
- - spec/dummy/app/views/forms/foo.html.erb
253
- - spec/dummy/app/views/forms/bar.html.erb
254
- - spec/dummy/app/views/layouts/mailer.text.erb
255
- - spec/dummy/app/views/layouts/application.html.erb
256
- - spec/dummy/app/views/layouts/mailer.html.erb
257
- - spec/dummy/app/rules/step1_rule.rb
258
- - spec/dummy/app/controllers/application_controller.rb
259
- - spec/dummy/app/controllers/forms_controller.rb
260
- - spec/dummy/app/models/application_record.rb
261
- - spec/dummy/app/models/stub_model.rb
262
- - spec/dummy/package.json
263
- - spec/dummy/config.ru
264
- - spec/dummy/bin/rails
265
- - spec/dummy/bin/setup
266
- - spec/dummy/bin/rake
267
- - spec/dummy/bin/update
268
- - spec/dummy/bin/yarn
269
- - spec/dummy/bin/bundle
266
+ - spec/dummy/config/puma.rb
267
+ - spec/dummy/config/application.rb
268
+ - spec/dummy/config/cable.yml
269
+ - spec/dummy/config/spring.rb
270
+ - spec/dummy/config/environments/test.rb
271
+ - spec/dummy/config/environments/development.rb
272
+ - spec/dummy/config/environments/production.rb
270
273
  - spec/form_spec.rb
271
- - spec/loader_spec.rb
272
274
  - spec/spec_helper.rb
273
- - spec/controllers/forms_controller_spec.rb