dynamic_fieldsets 0.0.2

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.
Files changed (119) hide show
  1. data/CHANGELOG +4 -0
  2. data/Gemfile +21 -0
  3. data/Gemfile.lock +157 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +69 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/dynamic_fieldsets/fields_controller.rb +75 -0
  9. data/app/controllers/dynamic_fieldsets/fieldset_associators_controller.rb +24 -0
  10. data/app/controllers/dynamic_fieldsets/fieldsets_controller.rb +89 -0
  11. data/app/helpers/dynamic_fieldsets/fields_helper.rb +19 -0
  12. data/app/helpers/dynamic_fieldsets_helper.rb +207 -0
  13. data/app/models/dynamic_fieldsets/field.rb +85 -0
  14. data/app/models/dynamic_fieldsets/field_default.rb +14 -0
  15. data/app/models/dynamic_fieldsets/field_html_attribute.rb +15 -0
  16. data/app/models/dynamic_fieldsets/field_option.rb +18 -0
  17. data/app/models/dynamic_fieldsets/field_record.rb +11 -0
  18. data/app/models/dynamic_fieldsets/fieldset.rb +57 -0
  19. data/app/models/dynamic_fieldsets/fieldset_associator.rb +76 -0
  20. data/app/views/dynamic_fieldsets/fields/_field_default_fields.html.erb +7 -0
  21. data/app/views/dynamic_fieldsets/fields/_field_html_attribute_fields.html.erb +8 -0
  22. data/app/views/dynamic_fieldsets/fields/_field_option_fields.html.erb +6 -0
  23. data/app/views/dynamic_fieldsets/fields/_form.html.erb +81 -0
  24. data/app/views/dynamic_fieldsets/fields/edit.html.erb +6 -0
  25. data/app/views/dynamic_fieldsets/fields/index.html.erb +29 -0
  26. data/app/views/dynamic_fieldsets/fields/new.html.erb +5 -0
  27. data/app/views/dynamic_fieldsets/fields/show.html.erb +70 -0
  28. data/app/views/dynamic_fieldsets/fieldset_associators/index.html.erb +18 -0
  29. data/app/views/dynamic_fieldsets/fieldset_associators/show.html.erb +26 -0
  30. data/app/views/dynamic_fieldsets/fieldsets/_form.html.erb +37 -0
  31. data/app/views/dynamic_fieldsets/fieldsets/children.html.erb +45 -0
  32. data/app/views/dynamic_fieldsets/fieldsets/edit.html.erb +6 -0
  33. data/app/views/dynamic_fieldsets/fieldsets/index.html.erb +31 -0
  34. data/app/views/dynamic_fieldsets/fieldsets/new.html.erb +5 -0
  35. data/app/views/dynamic_fieldsets/fieldsets/show.html.erb +31 -0
  36. data/config/routes.rb +9 -0
  37. data/dynamic_fieldsets.gemspec +195 -0
  38. data/lib/dynamic_fieldsets/config.rb +0 -0
  39. data/lib/dynamic_fieldsets/dynamic_fieldsets_in_model.rb +164 -0
  40. data/lib/dynamic_fieldsets/engine.rb +4 -0
  41. data/lib/dynamic_fieldsets/railtie.rb +13 -0
  42. data/lib/dynamic_fieldsets.rb +2 -0
  43. data/lib/generators/dynamic_fieldsets/install_generator.rb +44 -0
  44. data/lib/generators/dynamic_fieldsets/templates/config.rb +0 -0
  45. data/lib/generators/dynamic_fieldsets/templates/migrations/install_migration.rb +74 -0
  46. data/spec/dummy/Rakefile +7 -0
  47. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  48. data/spec/dummy/app/controllers/information_forms_controller.rb +85 -0
  49. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  50. data/spec/dummy/app/helpers/information_forms_helper.rb +2 -0
  51. data/spec/dummy/app/models/information_form.rb +3 -0
  52. data/spec/dummy/app/views/information_forms/_form.html.erb +22 -0
  53. data/spec/dummy/app/views/information_forms/edit.html.erb +6 -0
  54. data/spec/dummy/app/views/information_forms/index.html.erb +23 -0
  55. data/spec/dummy/app/views/information_forms/new.html.erb +5 -0
  56. data/spec/dummy/app/views/information_forms/show.html.erb +11 -0
  57. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  58. data/spec/dummy/config/application.rb +45 -0
  59. data/spec/dummy/config/boot.rb +10 -0
  60. data/spec/dummy/config/database.yml +22 -0
  61. data/spec/dummy/config/environment.rb +5 -0
  62. data/spec/dummy/config/environments/development.rb +26 -0
  63. data/spec/dummy/config/environments/production.rb +49 -0
  64. data/spec/dummy/config/environments/test.rb +35 -0
  65. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  66. data/spec/dummy/config/initializers/inflections.rb +10 -0
  67. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  68. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  69. data/spec/dummy/config/initializers/session_store.rb +8 -0
  70. data/spec/dummy/config/locales/en.yml +5 -0
  71. data/spec/dummy/config/routes.rb +60 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/db/migrate/20110726215814_create_dynamic_fieldsets_tables.rb +74 -0
  74. data/spec/dummy/db/migrate/20110727210451_create_information_forms.rb +13 -0
  75. data/spec/dummy/db/schema.rb +83 -0
  76. data/spec/dummy/features/field.feature +54 -0
  77. data/spec/dummy/features/fieldset.feature +68 -0
  78. data/spec/dummy/features/fieldset_associator.feature +20 -0
  79. data/spec/dummy/features/step_definitions/debugging_steps.rb +8 -0
  80. data/spec/dummy/features/step_definitions/field_steps.rb +63 -0
  81. data/spec/dummy/features/step_definitions/fieldset_associator_steps.rb +11 -0
  82. data/spec/dummy/features/step_definitions/fieldset_steps.rb +57 -0
  83. data/spec/dummy/features/step_definitions/web_steps.rb +214 -0
  84. data/spec/dummy/features/support/env.rb +15 -0
  85. data/spec/dummy/features/support/paths.rb +46 -0
  86. data/spec/dummy/features/support/selectors.rb +39 -0
  87. data/spec/dummy/public/404.html +26 -0
  88. data/spec/dummy/public/422.html +26 -0
  89. data/spec/dummy/public/500.html +26 -0
  90. data/spec/dummy/public/favicon.ico +0 -0
  91. data/spec/dummy/public/javascripts/application.js +2 -0
  92. data/spec/dummy/public/javascripts/jquery.min.js +166 -0
  93. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  94. data/spec/dummy/public/stylesheets/scaffold.css +56 -0
  95. data/spec/dummy/script/rails +6 -0
  96. data/spec/dynamic_fieldsets_helper_spec.rb +254 -0
  97. data/spec/dynamic_fieldsets_in_model_spec.rb +175 -0
  98. data/spec/dynamic_fieldsets_spec.rb +7 -0
  99. data/spec/integration/navigation_spec.rb +9 -0
  100. data/spec/models/field_default_spec.rb +26 -0
  101. data/spec/models/field_html_attribute_spec.rb +30 -0
  102. data/spec/models/field_option_spec.rb +52 -0
  103. data/spec/models/field_record_spec.rb +44 -0
  104. data/spec/models/field_spec.rb +169 -0
  105. data/spec/models/fieldset_associator_spec.rb +128 -0
  106. data/spec/models/fieldset_spec.rb +169 -0
  107. data/spec/reports/SPEC-ActsAsMultipartForm.xml +9 -0
  108. data/spec/reports/SPEC-MultipartForm-InProgressForm-validations.xml +47 -0
  109. data/spec/reports/SPEC-MultipartForm-InProgressForm.xml +7 -0
  110. data/spec/reports/SPEC-Navigation.xml +9 -0
  111. data/spec/spec_helper.rb +37 -0
  112. data/spec/support/field_default_helper.rb +12 -0
  113. data/spec/support/field_helper.rb +16 -0
  114. data/spec/support/field_html_attribute_helper.rb +14 -0
  115. data/spec/support/field_option_helper.rb +13 -0
  116. data/spec/support/field_record_helper.rb +12 -0
  117. data/spec/support/fieldset_associator_helper.rb +12 -0
  118. data/spec/support/fieldset_helper.rb +28 -0
  119. metadata +328 -0
@@ -0,0 +1,74 @@
1
+ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :fieldset_associators do |t|
4
+ t.integer :fieldset_id
5
+ t.integer :fieldset_model_id
6
+ t.string :fieldset_model_type
7
+ t.string :fieldset_model_name
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ create_table :fieldsets do |t|
13
+ t.string :nkey, :null => false
14
+ t.string :name
15
+ t.text :description
16
+ t.integer :parent_fieldset_id
17
+ t.integer :order_num
18
+
19
+ t.timestamps
20
+ end
21
+ add_index :fieldsets, :nkey, :unique => true
22
+
23
+
24
+ create_table :fields do |t|
25
+ t.integer :fieldset_id
26
+ t.string :name
27
+ t.string :label, :required => true
28
+ t.string :field_type, :required => true
29
+ t.boolean :required, :default => false
30
+ t.boolean :enabled, :default => true
31
+ t.integer :order_num, :required => true
32
+
33
+ t.timestamps
34
+ end
35
+
36
+ create_table :field_options do |t|
37
+ t.integer :field_id
38
+ t.string :name
39
+ t.boolean :enabled, :default => true
40
+
41
+ t.timestamps
42
+ end
43
+
44
+ create_table :field_defaults do |t|
45
+ t.integer :field_id
46
+ t.string :value
47
+
48
+ t.timestamps
49
+ end
50
+
51
+ create_table :field_html_attributes do |t|
52
+ t.integer :field_id
53
+ t.string :attribute_name, :required => true # couldn't use attribute because it is used by active record
54
+ t.string :value, :required => true
55
+
56
+ t.timestamps
57
+ end
58
+
59
+ create_table :field_records do |t|
60
+ t.integer :fieldset_associator_id
61
+ t.integer :field_id
62
+ t.text :value
63
+ end
64
+ end
65
+
66
+ def self.down
67
+ drop_table :fieldsets
68
+ drop_table :fields
69
+ drop_table :field_options
70
+ drop_table :field_defaults
71
+ drop_table :field_html_attributes
72
+ drop_table :field_records
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ class CreateInformationForms < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :information_forms do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :information_forms
12
+ end
13
+ end
@@ -0,0 +1,83 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended to check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(:version => 20110727210451) do
14
+
15
+ create_table "field_defaults", :force => true do |t|
16
+ t.integer "field_id"
17
+ t.string "value"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "field_html_attributes", :force => true do |t|
23
+ t.integer "field_id"
24
+ t.string "attribute_name"
25
+ t.string "value"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ create_table "field_options", :force => true do |t|
31
+ t.integer "field_id"
32
+ t.string "name"
33
+ t.boolean "enabled", :default => true
34
+ t.datetime "created_at"
35
+ t.datetime "updated_at"
36
+ end
37
+
38
+ create_table "field_records", :force => true do |t|
39
+ t.integer "fieldset_associator_id"
40
+ t.integer "field_id"
41
+ t.text "value"
42
+ end
43
+
44
+ create_table "fields", :force => true do |t|
45
+ t.integer "fieldset_id"
46
+ t.string "name"
47
+ t.string "label"
48
+ t.string "field_type"
49
+ t.boolean "required", :default => false
50
+ t.boolean "enabled", :default => true
51
+ t.integer "order_num"
52
+ t.datetime "created_at"
53
+ t.datetime "updated_at"
54
+ end
55
+
56
+ create_table "fieldset_associators", :force => true do |t|
57
+ t.integer "fieldset_id"
58
+ t.integer "fieldset_model_id"
59
+ t.string "fieldset_model_type"
60
+ t.string "fieldset_model_name"
61
+ t.datetime "created_at"
62
+ t.datetime "updated_at"
63
+ end
64
+
65
+ create_table "fieldsets", :force => true do |t|
66
+ t.string "nkey", :null => false
67
+ t.string "name"
68
+ t.text "description"
69
+ t.integer "parent_fieldset_id"
70
+ t.integer "order_num"
71
+ t.datetime "created_at"
72
+ t.datetime "updated_at"
73
+ end
74
+
75
+ add_index "fieldsets", ["nkey"], :name => "index_fieldsets_on_nkey", :unique => true
76
+
77
+ create_table "information_forms", :force => true do |t|
78
+ t.string "name"
79
+ t.datetime "created_at"
80
+ t.datetime "updated_at"
81
+ end
82
+
83
+ end
@@ -0,0 +1,54 @@
1
+ Feature: Managed fields
2
+
3
+ Scenario: Listing fields
4
+ Given a field exists
5
+ When I go to the field index page
6
+ Then I should see that field listed
7
+
8
+ Scenario: Adding a field
9
+ Given I am on the field new page
10
+ When I fill in "test_field" for "Label"
11
+ And I fill in "Test field" for "Name"
12
+ And I select "textfield" from "Field type"
13
+ And I fill in "1" for "Order Number"
14
+ And I press "Create Field"
15
+ Then I should be on the field show page for that field
16
+ And I should see "Successfully created a new field"
17
+ And I should see the data for that field
18
+
19
+ Scenario: Editing a field
20
+ Given a field exists
21
+ And I am on the field edit page for that field
22
+ When I fill in "Different field name" for "Name"
23
+ And I fill in "different_field_name" for "Label"
24
+ And I select "textarea" from "Field type"
25
+ And I press "Update Field"
26
+ Then I should be on the field show page for that field
27
+ And I should see "Successfully updated a field"
28
+ And I should see "Different field name"
29
+ And I should see "different_field_name"
30
+
31
+ Scenario: Destroying a field
32
+ Given a field exists
33
+ And I record the data for that field
34
+ And I am on the field index page
35
+ When I follow "Destroy"
36
+ Then I should not see that field listed
37
+
38
+ # this test should be a javascript test and actually test the javascript at some point
39
+ Scenario: Additional field links on new page
40
+ Given a field exists
41
+ And I am on the field new page
42
+ Then I should see "Add Field Option"
43
+ And I should see "Add Default Value"
44
+ And I should see "Add Html Attribute"
45
+
46
+ Scenario: Additional field values on show page
47
+ Given a field exists
48
+ And field options, defaults, and attributes exist for that field
49
+ When I go to the field show page for that field
50
+ Then I should see "Default value value"
51
+ And I should see "Field option value"
52
+ And I should see "Html attribute name"
53
+ And I should see "Html attribute value"
54
+
@@ -0,0 +1,68 @@
1
+ Feature: Managed fieldsets
2
+
3
+ Scenario: Listing fieldsets
4
+ Given a fieldset exists
5
+ When I go to the fieldset index page
6
+ Then I should see that fieldset listed
7
+
8
+ Scenario: Adding a root fieldset
9
+ Given I am on the fieldset new page
10
+ When I fill in "test_fieldset" for "Nkey"
11
+ And I fill in "Test Fieldset" for "Name"
12
+ And I fill in "This fieldset is being used for testing." for "Description"
13
+ And I press "Create Fieldset"
14
+ Then I should be on the fieldset show page for that fieldset
15
+ And I should see "Successfully created a new fieldset"
16
+ And I should see the data for that fieldset
17
+
18
+ Scenario: Adding a child fieldsets
19
+ Given a parent fieldset exists
20
+ And I am on the fieldset new page
21
+ When I fill in "test_fieldset" for "Nkey"
22
+ And I fill in "Test Fieldset" for "Name"
23
+ And I fill in "This fieldset is being used for testing." for "Description"
24
+ And I select "Parent Fieldset" from "Parent fieldset"
25
+ And I fill in "1" for "Order Number"
26
+ And I press "Create Fieldset"
27
+ Then I should be on the fieldset show page for that fieldset
28
+ And I should see "Successfully created a new fieldset"
29
+ And I should see the data for that fieldset
30
+
31
+ Scenario: Editing a fieldset
32
+ Given a parent fieldset exists
33
+ And I am on the fieldset edit page for that fieldset
34
+ When I fill in "Different fieldset name" for "Name"
35
+ And I fill in "different_fieldset_name" for "Nkey"
36
+ And I fill in "This fieldset has been repurposed" for "Description"
37
+ And I press "Update Fieldset"
38
+ Then I should be on the fieldset show page for that fieldset
39
+ And I should see "Successfully updated a fieldset"
40
+ And I should see "Different fieldset name"
41
+ And I should see "different_fieldset_name"
42
+ And I should see "This fieldset has been repurposed"
43
+
44
+ Scenario: Destroying a fieldset
45
+ Given a parent fieldset exists
46
+ And I record the data for that fieldset
47
+ And I am on the fieldset index page
48
+ When I follow "Destroy"
49
+ Then I should not see that fieldset listed
50
+
51
+ Scenario: Viewing child index page from the index page
52
+ Given a parent fieldset exists
53
+ And I am on the fieldset index page
54
+ When I follow "Children"
55
+ Then I should be on the fieldset child page for that fieldset
56
+
57
+ Scenario: Viewing a one generation fieldset's index page
58
+ And I am pending
59
+ Given a child fieldset exists
60
+ And I am on the child page of the parent fieldset
61
+ When I follow "Children"
62
+ Then I should be on the fieldset child page for that fieldset
63
+
64
+ Scenario: Viewing a fieldset's view page from the fieldset's child page
65
+ And I am pending
66
+ Given a parent fieldset exists
67
+
68
+
@@ -0,0 +1,20 @@
1
+ Feature: Managing fieldset associators
2
+
3
+ Scenario: I should be able to see all fieldset associators on the index page
4
+ Given a fieldset exists
5
+ And an information form exists
6
+ And a fieldset associator exists
7
+ When I go to the fieldset associator index page
8
+ Then I should see "InformationForm"
9
+ And I should see ":child_form"
10
+ And I should see "Fingerprint Form"
11
+
12
+ Scenario: I should be able to see a fieldset associator on the show page
13
+ Given a fieldset exists
14
+ And an information form exists
15
+ And a fieldset associator exists
16
+ When I go to the fieldset associator show page for that fieldset associator
17
+ Then I should see "InformationForm"
18
+ And I should see ":child_form"
19
+ And I should see "Fingerprint Form"
20
+
@@ -0,0 +1,8 @@
1
+ When /^I debug$/ do
2
+ debugger
3
+ end
4
+
5
+ When /^I am pending$/ do
6
+ pending "This scenario has not yet been completed."
7
+ end
8
+
@@ -0,0 +1,63 @@
1
+ Given /^a field exists$/ do
2
+ @field = DynamicFieldsets::Field.create(
3
+ :name => "Test field",
4
+ :label => "Test field",
5
+ :field_type => "textfield",
6
+ :order_num => 1,
7
+ :enabled => true,
8
+ :required => true)
9
+ end
10
+
11
+ Given /^field options, defaults, and attributes exist for that field$/ do
12
+ @field = DynamicFieldsets::Field.last
13
+ DynamicFieldsets::FieldOption.create(:field => @field, :name => "Field option value")
14
+ DynamicFieldsets::FieldDefault.create(:field => @field, :value => "Default value value")
15
+ DynamicFieldsets::FieldHtmlAttribute.create(:field => @field, :attribute_name => "Html attribute name", :value => "Html attribute value")
16
+ end
17
+
18
+ Then /^I should see that field listed$/ do
19
+ @field = DynamicFieldsets::Field.last
20
+ page.should have_content(@field.fieldset.name) if @field.fieldset
21
+ page.should have_content(@field.name)
22
+ page.should have_content(@field.field_type)
23
+ page.should have_content(@field.order_num)
24
+ end
25
+
26
+ Then /^I should see the data for that field$/ do
27
+ @field = DynamicFieldsets::Field.last
28
+ page.should have_content(@field.name)
29
+ page.should have_content(@field.label)
30
+ page.should have_content(@field.field_type)
31
+ page.should have_content(@field.order_num)
32
+ page.should have_content(@field.enabled)
33
+ page.should have_content(@field.required)
34
+
35
+ if @field.field_options.length > 0
36
+ @field.field_options.each do |fo|
37
+ page.should have_content(fo.name)
38
+ end
39
+ end
40
+
41
+ if @field.field_defaults.length > 0
42
+ @field.field_defaults.each do |fd|
43
+ page.should have_content(fd.value)
44
+ end
45
+ end
46
+
47
+ if @field.field_html_attributes.length > 0
48
+ @field.field_html_attributes.each do |fha|
49
+ page.should have_content(fha.attribute_name)
50
+ page.should have_content(fha.value)
51
+ end
52
+ end
53
+ end
54
+
55
+ Given /^I record the data for that field$/ do
56
+ @field = DynamicFieldsets::Field.last
57
+ end
58
+
59
+ Then /^I should not see that field listed$/ do
60
+ page.should_not have_content(@field.name)
61
+ page.should_not have_content(@field.field_type)
62
+ page.should_not have_content(@field.order_num)
63
+ end
@@ -0,0 +1,11 @@
1
+ Given /^an information form exists$/ do
2
+ @information_form = InformationForm.create(:name => "Test information form")
3
+ end
4
+
5
+ Given /^a fieldset associator exists$/ do
6
+ @fieldset_associator = DynamicFieldsets::FieldsetAssociator.create(
7
+ :fieldset_model_id => InformationForm.last.id,
8
+ :fieldset_model_type => "InformationForm",
9
+ :fieldset_model_name => ":child_form",
10
+ :fieldset_id => DynamicFieldsets::Fieldset.last.id)
11
+ end
@@ -0,0 +1,57 @@
1
+ Given(/^a fieldset exists$/) do
2
+ @fieldset = DynamicFieldsets::Fieldset.create(
3
+ :name => "Fingerprint Form",
4
+ :nkey => "fingerprint_form",
5
+ :description => "A test fingerprint form")
6
+ end
7
+
8
+ Given(/^a parent fieldset exists$/) do
9
+ @parent_fieldset = DynamicFieldsets::Fieldset.create(
10
+ :name => "Parent Fieldset",
11
+ :nkey => "parent_fieldset",
12
+ :description => "A test parent fieldset")
13
+ end
14
+
15
+ Given(/^a child fieldset exists$/) do
16
+ @parent_fieldset = DynamicFieldsets::Fieldset.create(
17
+ :name => "Parent Fieldset",
18
+ :nkey => "parent_fieldset",
19
+ :description => "A test parent fieldset")
20
+ @child_fieldset = DynamicFieldsets::Fieldset.create(
21
+ :name => "Child Fieldset",
22
+ :nkey => "child_fieldset",
23
+ :description => "A test parent fieldset",
24
+ :parent_fieldset => @parent_fieldset,
25
+ :order_num => 1)
26
+ end
27
+
28
+ Then(/^I should see that fieldset listed$/) do
29
+ @fieldset = DynamicFieldsets::Fieldset.last
30
+ page.should have_content(@fieldset.name)
31
+ page.should have_content(@fieldset.nkey)
32
+ page.should have_content(@fieldset.description)
33
+ page.should have_content(@fieldset.parent_fieldset.name) if @fieldset.parent_fieldset
34
+ end
35
+
36
+ Then(/^I should see the data for that fieldset$/) do
37
+ @fieldset = DynamicFieldsets::Fieldset.last
38
+ page.should have_content(@fieldset.name)
39
+ page.should have_content(@fieldset.nkey)
40
+ page.should have_content(@fieldset.description)
41
+ page.should have_content(@fieldset.parent_fieldset.name) if @fieldset.parent_fieldset
42
+ page.should have_content(@fieldset.order_num) if @fieldset.order_num
43
+ end
44
+ Given /^I record the data for that fieldset$/ do
45
+ @fieldset = DynamicFieldsets::Fieldset.last
46
+ end
47
+
48
+ # must call record the data for this to work
49
+ Then /^I should not see that fieldset listed$/ do
50
+ page.should_not have_content(@fieldset.name)
51
+ page.should_not have_content(@fieldset.nkey)
52
+ page.should_not have_content(@fieldset.description)
53
+ page.should_not have_content(@fieldset.parent_fieldset.name) if @fieldset.parent_fieldset
54
+ page.should_not have_content(@fieldset.order_num) if @fieldset.order_num
55
+ end
56
+
57
+
@@ -0,0 +1,214 @@
1
+ # TL;DR: YOU SHOULD DELETE THIS FILE
2
+ #
3
+ # This file was generated by Cucumber-Rails and is only here to get you a head start
4
+ # These step definitions are thin wrappers around the Capybara/Webrat API that lets you
5
+ # visit pages, interact with widgets and make assertions about page content.
6
+ #
7
+ # If you use these step definitions as basis for your features you will quickly end up
8
+ # with features that are:
9
+ #
10
+ # * Hard to maintain
11
+ # * Verbose to read
12
+ #
13
+ # A much better approach is to write your own higher level step definitions, following
14
+ # the advice in the following blog posts:
15
+ #
16
+ # * http://benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories.html
17
+ # * http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/
18
+ # * http://elabs.se/blog/15-you-re-cuking-it-wrong
19
+ #
20
+
21
+
22
+ require 'uri'
23
+ require 'cgi'
24
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
25
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "selectors"))
26
+
27
+ module WithinHelpers
28
+ def with_scope(locator)
29
+ locator ? within(*selector_for(locator)) { yield } : yield
30
+ end
31
+ end
32
+ World(WithinHelpers)
33
+
34
+ # Single-line step scoper
35
+ When /^(.*) within (.*[^:])$/ do |step, parent|
36
+ with_scope(parent) { When step }
37
+ end
38
+
39
+ # Multi-line step scoper
40
+ When /^(.*) within (.*[^:]):$/ do |step, parent, table_or_string|
41
+ with_scope(parent) { When "#{step}:", table_or_string }
42
+ end
43
+
44
+ Given /^(?:|I )am on (.+)$/ do |page_name|
45
+ visit path_to(page_name)
46
+ end
47
+
48
+ When /^(?:|I )go to (.+)$/ do |page_name|
49
+ visit path_to(page_name)
50
+ end
51
+
52
+ When /^(?:|I )press "([^"]*)"$/ do |button|
53
+ click_button(button)
54
+ end
55
+
56
+ When /^(?:|I )follow "([^"]*)"$/ do |link|
57
+ click_link(link)
58
+ end
59
+
60
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
61
+ fill_in(field, :with => value)
62
+ end
63
+
64
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"$/ do |value, field|
65
+ fill_in(field, :with => value)
66
+ end
67
+
68
+ # Use this to fill in an entire form with data from a table. Example:
69
+ #
70
+ # When I fill in the following:
71
+ # | Account Number | 5002 |
72
+ # | Expiry date | 2009-11-01 |
73
+ # | Note | Nice guy |
74
+ # | Wants Email? | |
75
+ #
76
+ # TODO: Add support for checkbox, select og option
77
+ # based on naming conventions.
78
+ #
79
+ When /^(?:|I )fill in the following:$/ do |fields|
80
+ fields.rows_hash.each do |name, value|
81
+ When %{I fill in "#{name}" with "#{value}"}
82
+ end
83
+ end
84
+
85
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"$/ do |value, field|
86
+ select(value, :from => field)
87
+ end
88
+
89
+ # moved to maniuplation steps
90
+ When /^(?:|I )check "([^"]*)"$/ do |field|
91
+ check(field)
92
+ end
93
+
94
+ When /^(?:|I )uncheck "([^"]*)"$/ do |field|
95
+ uncheck(field)
96
+ end
97
+
98
+ When /^(?:|I )choose "([^"]*)"$/ do |field|
99
+ choose(field)
100
+ end
101
+
102
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
103
+ attach_file(field, File.expand_path(path))
104
+ end
105
+
106
+ Then /^(?:|I )should see "([^"]*)"$/ do |text|
107
+ if page.respond_to? :should
108
+ page.should have_content(text)
109
+ else
110
+ assert page.has_content?(text)
111
+ end
112
+ end
113
+
114
+ Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
115
+ regexp = Regexp.new(regexp)
116
+
117
+ if page.respond_to? :should
118
+ page.should have_xpath('//*', :text => regexp)
119
+ else
120
+ assert page.has_xpath?('//*', :text => regexp)
121
+ end
122
+ end
123
+
124
+ Then /^(?:|I )should not see "([^"]*)"$/ do |text|
125
+ if page.respond_to? :should
126
+ page.should have_no_content(text)
127
+ else
128
+ assert page.has_no_content?(text)
129
+ end
130
+ end
131
+
132
+ Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
133
+ regexp = Regexp.new(regexp)
134
+
135
+ if page.respond_to? :should
136
+ page.should have_no_xpath('//*', :text => regexp)
137
+ else
138
+ assert page.has_no_xpath?('//*', :text => regexp)
139
+ end
140
+ end
141
+
142
+ Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
143
+ with_scope(parent) do
144
+ field = find_field(field)
145
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
146
+ if field_value.respond_to? :should
147
+ field_value.should =~ /#{value}/
148
+ else
149
+ assert_match(/#{value}/, field_value)
150
+ end
151
+ end
152
+ end
153
+
154
+ Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
155
+ with_scope(parent) do
156
+ field = find_field(field)
157
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
158
+ if field_value.respond_to? :should_not
159
+ field_value.should_not =~ /#{value}/
160
+ else
161
+ assert_no_match(/#{value}/, field_value)
162
+ end
163
+ end
164
+ end
165
+
166
+ # moved to generic steps
167
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
168
+ with_scope(parent) do
169
+ field_checked = find_field(label)['checked']
170
+ if field_checked.respond_to? :should
171
+ field_checked.should be_true
172
+ else
173
+ assert field_checked
174
+ end
175
+ end
176
+ end
177
+
178
+ # moved to generic steps
179
+ Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
180
+ with_scope(parent) do
181
+ field_checked = find_field(label)['checked']
182
+ if field_checked.respond_to? :should
183
+ field_checked.should be_false
184
+ else
185
+ assert !field_checked
186
+ end
187
+ end
188
+ end
189
+
190
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
191
+ current_path = URI.parse(current_url).path
192
+ if current_path.respond_to? :should
193
+ current_path.should == path_to(page_name)
194
+ else
195
+ assert_equal path_to(page_name), current_path
196
+ end
197
+ end
198
+
199
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
200
+ query = URI.parse(current_url).query
201
+ actual_params = query ? CGI.parse(query) : {}
202
+ expected_params = {}
203
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
204
+
205
+ if actual_params.respond_to? :should
206
+ actual_params.should == expected_params
207
+ else
208
+ assert_equal expected_params, actual_params
209
+ end
210
+ end
211
+
212
+ Then /^show me the page$/ do
213
+ save_and_open_page
214
+ end
@@ -0,0 +1,15 @@
1
+ require 'ruby-debug'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
4
+ #require 'dynamic_fieldsets'
5
+
6
+ require 'cucumber/rails'
7
+ # require 'rspec/expectations'
8
+
9
+ # Remove/comment out the lines below if your app doesn't have a database.
10
+ # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
11
+ begin
12
+ DatabaseCleaner.strategy = :transaction
13
+ rescue NameError
14
+ raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
15
+ end