formbuilder-rb 0.0.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +14 -0
  7. data/Gemfile.lock +219 -0
  8. data/Guardfile +17 -0
  9. data/{MIT-LICENSE → LICENSE.md} +1 -1
  10. data/README.md +86 -0
  11. data/app/controllers/formbuilder/concerns/forms_controller.rb +59 -0
  12. data/app/models/formbuilder/entry_attachment.rb +2 -8
  13. data/app/models/formbuilder/form.rb +53 -0
  14. data/app/models/formbuilder/response_field.rb +23 -10
  15. data/app/models/formbuilder/response_field_address.rb +12 -1
  16. data/app/models/formbuilder/response_field_checkboxes.rb +38 -0
  17. data/app/models/formbuilder/response_field_date.rb +7 -1
  18. data/app/models/formbuilder/response_field_dropdown.rb +2 -1
  19. data/app/models/formbuilder/response_field_email.rb +14 -2
  20. data/app/models/formbuilder/response_field_file.rb +75 -20
  21. data/app/models/formbuilder/response_field_number.rb +9 -2
  22. data/app/models/formbuilder/response_field_page_break.rb +13 -0
  23. data/app/models/formbuilder/response_field_paragraph.rb +19 -3
  24. data/app/models/formbuilder/response_field_price.rb +10 -6
  25. data/app/models/formbuilder/response_field_radio.rb +11 -2
  26. data/app/models/formbuilder/response_field_section_break.rb +12 -2
  27. data/app/models/formbuilder/response_field_table.rb +222 -0
  28. data/app/models/formbuilder/response_field_text.rb +9 -2
  29. data/app/models/formbuilder/response_field_time.rb +8 -1
  30. data/app/models/formbuilder/response_field_website.rb +26 -2
  31. data/app/uploaders/formbuilder/entry_attachment_uploader.rb +11 -1
  32. data/bin/rails +8 -0
  33. data/circle.yml +9 -0
  34. data/config/spring.rb +1 -0
  35. data/db/migrate/20130924185815_create_formbuilder_entry_attachments.rb +1 -0
  36. data/formbuilder-rb.gemspec +41 -0
  37. data/formbuilder-rb.sublime-project +20 -0
  38. data/lib/formbuilder.rb +8 -3
  39. data/lib/formbuilder/entry.rb +102 -159
  40. data/lib/formbuilder/entry_validator.rb +13 -6
  41. data/lib/formbuilder/version.rb +1 -1
  42. data/lib/formbuilder/views/entry_dl.rb +56 -0
  43. data/lib/formbuilder/views/form.rb +81 -0
  44. data/lib/formbuilder/views/form_field.rb +45 -0
  45. data/spec/controllers/formbuilder/forms_controller_spec.rb +40 -0
  46. data/spec/dummy/.ruby-gemset +1 -0
  47. data/spec/dummy/.ruby-version +1 -0
  48. data/spec/dummy/README.rdoc +28 -0
  49. data/spec/dummy/Rakefile +6 -0
  50. data/spec/dummy/app/assets/images/.keep +0 -0
  51. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  52. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  53. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  54. data/spec/dummy/app/controllers/forms_controller.rb +3 -0
  55. data/spec/dummy/app/controllers/test_controller.rb +57 -0
  56. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  57. data/spec/dummy/app/mailers/.keep +0 -0
  58. data/spec/dummy/app/models/concerns/.keep +0 -0
  59. data/spec/dummy/app/models/entry.rb +7 -0
  60. data/spec/dummy/app/models/entry_with_alternate_column_name.rb +11 -0
  61. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  62. data/spec/dummy/app/views/test/_form.rb +2 -0
  63. data/spec/dummy/app/views/test/render_entry.html.erb +1 -0
  64. data/spec/dummy/app/views/test/show_form.html.erb +1 -0
  65. data/spec/dummy/bin/bundle +3 -0
  66. data/spec/dummy/bin/rails +4 -0
  67. data/spec/dummy/bin/rake +4 -0
  68. data/spec/dummy/config.ru +4 -0
  69. data/spec/dummy/config/application.rb +25 -0
  70. data/spec/dummy/config/boot.rb +5 -0
  71. data/spec/dummy/config/database.yml.ci +15 -0
  72. data/spec/dummy/config/database.yml.example +15 -0
  73. data/spec/dummy/config/environment.rb +5 -0
  74. data/spec/dummy/config/environments/development.rb +29 -0
  75. data/spec/dummy/config/environments/production.rb +80 -0
  76. data/spec/dummy/config/environments/test.rb +52 -0
  77. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  78. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  79. data/spec/dummy/config/initializers/inflections.rb +16 -0
  80. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  81. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  82. data/spec/dummy/config/initializers/session_store.rb +3 -0
  83. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  84. data/spec/dummy/config/locales/en.yml +23 -0
  85. data/spec/dummy/config/routes.rb +12 -0
  86. data/spec/dummy/db/migrate/20130924182939_create_entries.rb +13 -0
  87. data/spec/dummy/db/migrate/20130924192151_create_formbuilder_forms.formbuilder.rb +11 -0
  88. data/spec/dummy/db/migrate/20130924192152_create_formbuilder_response_fields.formbuilder.rb +17 -0
  89. data/spec/dummy/db/migrate/20130926205845_create_formbuilder_entry_attachments.formbuilder.rb +12 -0
  90. data/spec/dummy/db/migrate/20140128000000_create_entry_with_alternate_column_names.rb +13 -0
  91. data/spec/dummy/db/schema.rb +64 -0
  92. data/spec/dummy/lib/assets/.keep +0 -0
  93. data/spec/dummy/log/.keep +0 -0
  94. data/spec/dummy/public/404.html +58 -0
  95. data/spec/dummy/public/422.html +58 -0
  96. data/spec/dummy/public/500.html +57 -0
  97. data/spec/dummy/public/favicon.ico +0 -0
  98. data/spec/dummy/test/fixtures/entries.yml +9 -0
  99. data/spec/dummy/test/fixtures/response_fields.yml +19 -0
  100. data/spec/dummy/test/models/entry_test.rb +7 -0
  101. data/spec/dummy/test/models/response_field_test.rb +7 -0
  102. data/spec/factories/formbuilder_forms.rb +45 -0
  103. data/spec/features/form_renderer_spec.rb +30 -0
  104. data/spec/features/submitting_an_entry_spec.rb +79 -0
  105. data/spec/fixtures/test_files/text.txt +1 -0
  106. data/spec/fixtures/test_files/text2.txt +1 -0
  107. data/spec/lib/formbuilder/entry_spec.rb +199 -0
  108. data/spec/lib/formbuilder/entry_validator_spec.rb +215 -0
  109. data/spec/lib/formbuilder/entry_with_alternate_column_name_spec.rb +37 -0
  110. data/spec/lib/formbuilder/views/entry_dl_spec.rb +38 -0
  111. data/spec/models/formbuilder/entry_attachment_spec.rb +17 -0
  112. data/spec/models/formbuilder/form_spec.rb +100 -0
  113. data/spec/models/formbuilder/response_field_address_spec.rb +25 -0
  114. data/spec/models/formbuilder/response_field_checkboxes_spec.rb +57 -0
  115. data/spec/models/formbuilder/response_field_file_spec.rb +80 -0
  116. data/spec/models/formbuilder/response_field_paragraph_spec.rb +22 -0
  117. data/spec/models/formbuilder/response_field_radio_spec.rb +30 -0
  118. data/spec/models/formbuilder/response_field_spec.rb +21 -0
  119. data/spec/models/formbuilder/response_field_table_spec.rb +124 -0
  120. data/spec/spec_helper.rb +25 -0
  121. data/spec/support/database_cleaner.rb +21 -0
  122. data/spec/support/submitting_an_entry_spec_helper.rb +151 -0
  123. metadata +286 -44
  124. data/app/controllers/formbuilder/forms_controller.rb +0 -53
  125. data/lib/formbuilder/entry_renderer.rb +0 -47
  126. data/lib/formbuilder/entry_table_renderer.rb +0 -58
  127. data/lib/formbuilder/form_renderer.rb +0 -102
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20140128000000) do
15
+
16
+ # These are extensions that must be enabled in order to support this database
17
+ enable_extension "plpgsql"
18
+ enable_extension "hstore"
19
+
20
+ create_table "entries", force: true do |t|
21
+ t.integer "form_id"
22
+ t.hstore "responses", default: {}, null: false
23
+ t.text "responses_text"
24
+ t.datetime "created_at"
25
+ t.datetime "updated_at"
26
+ end
27
+
28
+ create_table "entry_with_alternate_column_names", force: true do |t|
29
+ t.integer "form_id"
30
+ t.hstore "responses_alt", default: {}, null: false
31
+ t.text "responses_alt_text"
32
+ t.datetime "created_at"
33
+ t.datetime "updated_at"
34
+ end
35
+
36
+ create_table "formbuilder_entry_attachments", force: true do |t|
37
+ t.string "upload"
38
+ t.string "content_type"
39
+ t.integer "file_size"
40
+ t.datetime "created_at"
41
+ t.datetime "updated_at"
42
+ end
43
+
44
+ create_table "formbuilder_forms", force: true do |t|
45
+ t.integer "formable_id"
46
+ t.string "formable_type"
47
+ t.datetime "created_at"
48
+ t.datetime "updated_at"
49
+ end
50
+
51
+ create_table "formbuilder_response_fields", force: true do |t|
52
+ t.integer "form_id"
53
+ t.text "label"
54
+ t.string "type"
55
+ t.text "field_options"
56
+ t.integer "sort_order"
57
+ t.boolean "required", default: false
58
+ t.boolean "blind", default: false
59
+ t.boolean "admin_only", default: false
60
+ t.datetime "created_at"
61
+ t.datetime "updated_at"
62
+ end
63
+
64
+ end
File without changes
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ responses:
5
+ responses_text: MyText
6
+
7
+ two:
8
+ responses:
9
+ responses_text: MyText
@@ -0,0 +1,19 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ label: MyText
5
+ type:
6
+ field_options: MyText
7
+ sort_order: 1
8
+ required: false
9
+ blind: false
10
+ admin_only: false
11
+
12
+ two:
13
+ label: MyText
14
+ type:
15
+ field_options: MyText
16
+ sort_order: 1
17
+ required: false
18
+ blind: false
19
+ admin_only: false
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class EntryTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class ResponseFieldTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,45 @@
1
+ FactoryGirl.define do
2
+ factory :form, class: Formbuilder::Form do
3
+ end
4
+
5
+ factory :kitchen_sink_form, parent: :form do
6
+ after(:create) do |f|
7
+ options = [{'checked' => 'false', 'label' => 'Choice #1'}, {'checked' => 'false', 'label' => 'Choice #2'}]
8
+
9
+ # @todo fix these required fields to match :form_with_one_field
10
+ f.response_fields.create(label: "Text", type: "Formbuilder::ResponseFieldText", sort_order: 0)
11
+ f.response_fields.create(label: "Paragraph", type: "Formbuilder::ResponseFieldParagraph", sort_order: 1, field_options: {"size" => 'large', "required" => true, "description" => "How would you complete this project?"})
12
+ f.response_fields.create(label: "Checkboxes", type: "Formbuilder::ResponseFieldCheckboxes", sort_order: 2, field_options: {"options" => options, "required" => true})
13
+ f.response_fields.create(label: "THE SECTION!", type: "Formbuilder::ResponseFieldSectionBreak", sort_order: 3)
14
+ f.response_fields.create(label: "Radio", type: "Formbuilder::ResponseFieldRadio", sort_order: 4, field_options: {"options" => options, "required" => true})
15
+ f.response_fields.create(label: "Dropdown", type: "Formbuilder::ResponseFieldDropdown", sort_order: 5, field_options: {"options" => options, "required" => true, "include_blank_option" => true})
16
+ f.response_fields.create(label: "Price", type: "Formbuilder::ResponseFieldPrice", sort_order: 6, field_options: {"required" => true})
17
+ f.response_fields.create(label: "Number", type: "Formbuilder::ResponseFieldNumber", sort_order: 7, field_options: {"required" => true, "units" => "things"})
18
+ f.response_fields.create(label: "Date", type: "Formbuilder::ResponseFieldDate", sort_order: 8, field_options: {"required" => true})
19
+ f.response_fields.create(label: "Time", type: "Formbuilder::ResponseFieldTime", sort_order: 9, field_options: {"required" => true})
20
+ f.response_fields.create(label: "Website", type: "Formbuilder::ResponseFieldWebsite", sort_order: 10, field_options: {"required" => true})
21
+ f.response_fields.create(label: "File", type: "Formbuilder::ResponseFieldFile", sort_order: 11, field_options: {"required" => true})
22
+ f.response_fields.create(label: "Email", type: "Formbuilder::ResponseFieldEmail", sort_order: 12, field_options: {"required" => true})
23
+ f.response_fields.create(label: "Address", type: "Formbuilder::ResponseFieldAddress", sort_order: 13, field_options: {"required" => true})
24
+ f.response_fields.create(label: "Table", type: "Formbuilder::ResponseFieldTable", sort_order: 14,
25
+ field_options: {"columns" => [{'label' => 'column one'}, {'label' => 'column two'}],
26
+ "minrows" => "2"})
27
+ end
28
+ end
29
+
30
+ factory :three_page_form, parent: :form do
31
+ after(:create) do |f|
32
+ f.response_fields.create(label: "Text1", type: "Formbuilder::ResponseFieldText", sort_order: 0, required: true)
33
+ f.response_fields.create(type: "Formbuilder::ResponseFieldPageBreak", sort_order: 1)
34
+ f.response_fields.create(label: "Text2", type: "Formbuilder::ResponseFieldText", sort_order: 2, required: true)
35
+ f.response_fields.create(type: "Formbuilder::ResponseFieldPageBreak", sort_order: 3)
36
+ f.response_fields.create(label: "Text3", type: "Formbuilder::ResponseFieldText", sort_order: 4, required: true)
37
+ end
38
+ end
39
+
40
+ factory :form_with_one_field, parent: :form do
41
+ after(:create) do |f|
42
+ f.response_fields.create(label: "Text", type: "Formbuilder::ResponseFieldText", sort_order: 0, required: true)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ include SubmittingAnEntrySpecHelper
3
+
4
+ describe 'Rendering a form properly' do
5
+
6
+ subject { page }
7
+ let!(:form) { FactoryGirl.create(:form) }
8
+ let!(:entry) { Entry.create(form: form, skip_validation: true) }
9
+
10
+ context 'with a text field' do
11
+
12
+ before do
13
+ @rf = form.response_fields.create(label: "Textfield", type: "Formbuilder::ResponseFieldText", sort_order: 0)
14
+ visit test_form_path(form.id, entry.id)
15
+ end
16
+
17
+ it 'should render the field and its label' do
18
+ page.should have_text 'Textfield'
19
+ page.should have_field "response_fields_#{@rf.id}"
20
+ end
21
+
22
+ it 'should render errors'
23
+
24
+ it 'should render length validations'
25
+
26
+ it 'should render min/max validations'
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+ include SubmittingAnEntrySpecHelper
3
+
4
+ describe 'Submitting an entry' do
5
+
6
+ subject { page }
7
+
8
+ describe 'kitchen sink' do
9
+ let!(:form) { FactoryGirl.create(:kitchen_sink_form) }
10
+ let!(:entry) { e = Entry.new(form: form); e.save(skip_validation: true); e }
11
+
12
+ before do
13
+ visit test_form_path(form.id, entry.id)
14
+ end
15
+
16
+ it 'should render the form fields properly' do
17
+ form.input_fields.each do |response_field|
18
+ page.should have_selector('label', text: response_field.label)
19
+ end
20
+ end
21
+
22
+ it 'should save and then submit responses' do
23
+ test_field_values.each do |k, v|
24
+ set_field(k, v)
25
+ end
26
+
27
+ save_draft_and_refresh
28
+
29
+ normalized_test_field_values.each do |k, v|
30
+ ensure_field(k, v)
31
+ end
32
+
33
+ # and update the draft
34
+ test_field_values_two.each do |k, v|
35
+ set_field(k, v)
36
+ end
37
+
38
+ save_draft_and_refresh
39
+
40
+ normalized_test_field_values_two.each do |k, v|
41
+ ensure_field(k, v)
42
+ end
43
+ end
44
+ end
45
+
46
+ describe 'multi-page form' do
47
+ let!(:form) { FactoryGirl.create(:three_page_form) }
48
+ let!(:entry) { Entry.create(form: form, skip_validation: true) }
49
+
50
+ it 'renders the pages properly' do
51
+ visit test_form_path(form.id, entry.id)
52
+ page.should have_selector('label', text: 'Text1')
53
+ page.should_not have_selector('label', text: 'Text2')
54
+ page.should_not have_selector('label', text: 'Text3')
55
+
56
+ visit test_form_path(form.id, entry.id, page: 2)
57
+ page.should_not have_selector('label', text: 'Text1')
58
+ page.should have_selector('label', text: 'Text2')
59
+ page.should_not have_selector('label', text: 'Text3')
60
+
61
+ visit test_form_path(form.id, entry.id, page: 3)
62
+ page.should_not have_selector('label', text: 'Text1')
63
+ page.should_not have_selector('label', text: 'Text2')
64
+ page.should have_selector('label', text: 'Text3')
65
+ end
66
+
67
+ it 'ignores errors for previous pages, unless on the last page' do
68
+ visit test_form_path(form.id, entry.id, page: 1)
69
+ fill_in 'Text1', with: 'hi'
70
+ click_button 'Next page'
71
+ visit test_form_path(form.id, entry.id, page: 3)
72
+ fill_in 'Text3', with: 'bye'
73
+ click_button 'Submit'
74
+ uri = URI.parse(current_url)
75
+ expect("#{uri.path}?#{uri.query}").to eq test_form_path(form.id, entry.id, page: 2)
76
+ end
77
+ end
78
+
79
+ end