dynamic_fieldsets 0.0.3 → 0.0.4

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 (89) hide show
  1. data/CHANGELOG +7 -0
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +1 -0
  4. data/README.rdoc +15 -2
  5. data/Rakefile +24 -4
  6. data/VERSION +1 -1
  7. data/app/controllers/dynamic_fieldsets/fields_controller.rb +25 -0
  8. data/app/controllers/dynamic_fieldsets/fieldset_children_controller.rb +57 -0
  9. data/app/controllers/dynamic_fieldsets/fieldsets_controller.rb +91 -5
  10. data/app/helpers/dynamic_fieldsets/fields_helper.rb +1 -15
  11. data/app/helpers/dynamic_fieldsets/fieldset_children_helper.rb +5 -0
  12. data/app/helpers/dynamic_fieldsets/nested_model_helper.rb +18 -0
  13. data/app/helpers/dynamic_fieldsets_helper.rb +70 -44
  14. data/app/models/dynamic_fieldsets/dependency.rb +76 -0
  15. data/app/models/dynamic_fieldsets/dependency_clause.rb +32 -0
  16. data/app/models/dynamic_fieldsets/dependency_group.rb +108 -0
  17. data/app/models/dynamic_fieldsets/field.rb +17 -12
  18. data/app/models/dynamic_fieldsets/field_default.rb +27 -1
  19. data/app/models/dynamic_fieldsets/field_record.rb +19 -4
  20. data/app/models/dynamic_fieldsets/fieldset.rb +35 -30
  21. data/app/models/dynamic_fieldsets/fieldset_associator.rb +52 -8
  22. data/app/models/dynamic_fieldsets/fieldset_child.rb +148 -0
  23. data/app/views/dynamic_fieldsets/fields/_disable_field_form.html.erb +4 -0
  24. data/app/views/dynamic_fieldsets/fields/_field_default_fields.html.erb +1 -1
  25. data/app/views/dynamic_fieldsets/fields/_form.html.erb +9 -27
  26. data/app/views/dynamic_fieldsets/fields/index.html.erb +8 -5
  27. data/app/views/dynamic_fieldsets/fields/new.html.erb +5 -1
  28. data/app/views/dynamic_fieldsets/fields/show.html.erb +1 -13
  29. data/app/views/dynamic_fieldsets/fieldset_children/_dependency_clause_fields.html.erb +25 -0
  30. data/app/views/dynamic_fieldsets/fieldset_children/_dependency_fields.html.erb +12 -0
  31. data/app/views/dynamic_fieldsets/fieldset_children/_dependency_group_fields.html.erb +16 -0
  32. data/app/views/dynamic_fieldsets/fieldset_children/_form.html.erb +34 -0
  33. data/app/views/dynamic_fieldsets/fieldset_children/edit.html.erb +6 -0
  34. data/app/views/dynamic_fieldsets/fieldsets/_associate_child.html.erb +4 -0
  35. data/app/views/dynamic_fieldsets/fieldsets/_child.html.erb +41 -0
  36. data/app/views/dynamic_fieldsets/fieldsets/_form.html.erb +2 -8
  37. data/app/views/dynamic_fieldsets/fieldsets/children.html.erb +47 -39
  38. data/app/views/dynamic_fieldsets/fieldsets/index.html.erb +4 -4
  39. data/app/views/dynamic_fieldsets/fieldsets/new.html.erb +5 -1
  40. data/app/views/dynamic_fieldsets/fieldsets/reorder.html.erb +4 -0
  41. data/app/views/dynamic_fieldsets/fieldsets/show.html.erb +1 -12
  42. data/app/views/dynamic_fieldsets/shared/_javascript_watcher.html.erb +255 -0
  43. data/app/views/dynamic_fieldsets/shared/_nested_model_javascript.html.erb +35 -0
  44. data/config/.routes.rb.swp +0 -0
  45. data/config/routes.rb +11 -0
  46. data/dynamic_fieldsets.gemspec +41 -4
  47. data/lib/dynamic_fieldsets/dynamic_fieldsets_in_model.rb +141 -14
  48. data/lib/generators/dynamic_fieldsets/templates/migrations/install_migration.rb +39 -5
  49. data/spec/dummy/app/controllers/information_forms_controller.rb +2 -1
  50. data/spec/dummy/app/models/information_form.rb +1 -1
  51. data/spec/dummy/app/views/information_forms/dynamic_view.html.erb +18 -0
  52. data/spec/dummy/app/views/information_forms/show.html.erb +1 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +9 -1
  54. data/spec/dummy/config/routes.rb +1 -1
  55. data/spec/dummy/db/migrate/{20110726215814_create_dynamic_fieldsets_tables.rb → 20110809161724_create_dynamic_fieldsets_tables.rb} +39 -5
  56. data/spec/dummy/db/schema.rb +40 -11
  57. data/spec/dummy/features/field.feature +17 -2
  58. data/spec/dummy/features/fieldset.feature +1 -21
  59. data/spec/dummy/features/fieldset_children.feature +50 -0
  60. data/spec/dummy/features/javascript_tests.feature +91 -0
  61. data/spec/dummy/features/step_definitions/field_steps.rb +9 -5
  62. data/spec/dummy/features/step_definitions/fieldset_associator_steps.rb +3 -1
  63. data/spec/dummy/features/step_definitions/fieldset_children_steps.rb +65 -0
  64. data/spec/dummy/features/step_definitions/fieldset_steps.rb +0 -27
  65. data/spec/dummy/features/step_definitions/javascript_steps.rb +208 -0
  66. data/spec/dummy/features/step_definitions/web_steps.rb +5 -0
  67. data/spec/dummy/features/support/paths.rb +10 -1
  68. data/spec/dummy/features/support/selectors.rb +2 -0
  69. data/spec/dummy/public/javascripts/jquery-1.6.2.min.js +18 -0
  70. data/spec/dummy/public/javascripts/jquery-ui-1.8.15.custom.min.js +111 -0
  71. data/spec/dummy/public/javascripts/jquery-ui-nestedSortable.js +356 -0
  72. data/spec/dummy/public/stylesheets/scaffold.css +101 -0
  73. data/spec/dynamic_fieldsets_helper_spec.rb +236 -55
  74. data/spec/dynamic_fieldsets_in_model_spec.rb +122 -4
  75. data/spec/models/dependency_clause_spec.rb +55 -0
  76. data/spec/models/dependency_group_spec.rb +237 -0
  77. data/spec/models/dependency_spec.rb +173 -0
  78. data/spec/models/field_default_spec.rb +49 -0
  79. data/spec/models/field_record_spec.rb +11 -2
  80. data/spec/models/field_spec.rb +30 -6
  81. data/spec/models/fieldset_associator_spec.rb +138 -25
  82. data/spec/models/fieldset_child_spec.rb +122 -0
  83. data/spec/models/fieldset_spec.rb +78 -80
  84. data/spec/support/dependency_group_helper.rb +9 -0
  85. data/spec/support/dependency_helper.rb +13 -0
  86. data/spec/support/field_helper.rb +0 -2
  87. data/spec/support/fieldset_child_helper.rb +10 -0
  88. data/spec/support/fieldset_helper.rb +2 -18
  89. metadata +51 -5
@@ -9,12 +9,19 @@ class <%= migration_class_name %> < ActiveRecord::Migration
9
9
  t.timestamps
10
10
  end
11
11
 
12
+ create_table :fieldset_children do |t|
13
+ t.integer :fieldset_id
14
+ t.integer :child_id
15
+ t.string :child_type
16
+ t.integer :order_num
17
+
18
+ t.timestamps
19
+ end
20
+
12
21
  create_table :fieldsets do |t|
13
22
  t.string :nkey, :null => false
14
23
  t.string :name
15
24
  t.text :description
16
- t.integer :parent_fieldset_id
17
- t.integer :order_num
18
25
 
19
26
  t.timestamps
20
27
  end
@@ -22,13 +29,11 @@ class <%= migration_class_name %> < ActiveRecord::Migration
22
29
 
23
30
 
24
31
  create_table :fields do |t|
25
- t.integer :fieldset_id
26
32
  t.string :name
27
33
  t.string :label, :required => true
28
34
  t.string :field_type, :required => true
29
35
  t.boolean :required, :default => false
30
36
  t.boolean :enabled, :default => true
31
- t.integer :order_num, :required => true
32
37
 
33
38
  t.timestamps
34
39
  end
@@ -58,17 +63,46 @@ class <%= migration_class_name %> < ActiveRecord::Migration
58
63
 
59
64
  create_table :field_records do |t|
60
65
  t.integer :fieldset_associator_id
61
- t.integer :field_id
66
+ t.integer :fieldset_child_id
62
67
  t.text :value
68
+
69
+ t.timestamps
70
+ end
71
+
72
+ create_table :dependencies do |t|
73
+ t.integer :fieldset_child_id
74
+ t.string :value
75
+ t.string :relationship
76
+ t.integer :dependency_clause_id
77
+
78
+ t.timestamps
79
+ end
80
+
81
+ create_table :dependency_clauses do |t|
82
+ t.integer :dependency_group_id
83
+
84
+ t.timestamps
85
+ end
86
+
87
+ create_table :dependency_groups do |t|
88
+ t.string :action
89
+ t.integer :fieldset_child_id
90
+
91
+ t.timestamps
63
92
  end
64
93
  end
65
94
 
66
95
  def self.down
67
96
  drop_table :fieldsets
97
+ drop_table :fieldset_children
68
98
  drop_table :fields
69
99
  drop_table :field_options
70
100
  drop_table :field_defaults
71
101
  drop_table :field_html_attributes
72
102
  drop_table :field_records
103
+
104
+ drop_table :dependencies
105
+ drop_table :dependency_clauses
106
+ drop_table :dependency_group
73
107
  end
74
108
  end
@@ -42,6 +42,7 @@ class InformationFormsController < ApplicationController
42
42
  # POST /information_forms.xml
43
43
  def create
44
44
  @information_form = InformationForm.new(params[:information_form])
45
+ @information_form.set_fieldset_values( params )
45
46
 
46
47
  respond_to do |format|
47
48
  if @information_form.save
@@ -58,7 +59,7 @@ class InformationFormsController < ApplicationController
58
59
  # PUT /information_forms/1.xml
59
60
  def update
60
61
  @information_form = InformationForm.find(params[:id])
61
- @information_form.dynamic_fieldset_values = params.select{ |key, value| key.match(/^fsa-/) }
62
+ @information_form.set_fieldset_values( params )
62
63
 
63
64
  respond_to do |format|
64
65
  if @information_form.update_attributes(params[:information_form])
@@ -1,3 +1,3 @@
1
1
  class InformationForm < ActiveRecord::Base
2
- acts_as_dynamic_fieldset :child_form => {:fieldset => :information_fieldset}, :parent_form => {:fieldset => :information_fieldset}
2
+ acts_as_dynamic_fieldset :child_form => {:fieldset => :first}
3
3
  end
@@ -0,0 +1,18 @@
1
+ <%= form_for(@information_form) do |f| %>
2
+ <% if @information_form.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@information_form.errors.count, "error") %> prohibited this information_form from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @information_form.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <%= dynamic_fieldset_form_renderer(@information_form.child_form) %>
15
+ <div class="actions">
16
+ <%= f.submit %>
17
+ </div>
18
+ <% end %>
@@ -5,6 +5,7 @@
5
5
  <%= @information_form.name %>
6
6
  </p>
7
7
 
8
+
8
9
  <%= dynamic_fieldset_show_renderer(@information_form.child_form) %>
9
10
 
10
11
  <%= link_to 'Edit', edit_information_form_path(@information_form) %> |
@@ -4,11 +4,19 @@
4
4
  <title>Dummy</title>
5
5
  <%= stylesheet_link_tag :all %>
6
6
  <%= javascript_include_tag :defaults %>
7
- <%= javascript_include_tag "jquery.min" %>
7
+ <%= javascript_include_tag "jquery-1.6.2.min" %>
8
+ <%= javascript_include_tag "jquery-ui-1.8.15.custom.min" %>
9
+ <%= javascript_include_tag "jquery-ui-nestedSortable" %>
8
10
  <%= csrf_meta_tag %>
9
11
  </head>
10
12
  <body>
11
13
 
14
+ <% unless flash[:notice].blank? %>
15
+ <div id='notice'>
16
+ <%= flash[:notice] %>
17
+ </div>
18
+ <% end %>
19
+
12
20
  <%= yield %>
13
21
 
14
22
  </body>
@@ -1,6 +1,6 @@
1
1
  Dummy::Application.routes.draw do
2
2
  resources :information_forms
3
-
3
+
4
4
  # The priority is based upon order of creation:
5
5
  # first created -> highest priority.
6
6
 
@@ -9,12 +9,19 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
9
9
  t.timestamps
10
10
  end
11
11
 
12
+ create_table :fieldset_children do |t|
13
+ t.integer :fieldset_id
14
+ t.integer :child_id
15
+ t.string :child_type
16
+ t.integer :order_num
17
+
18
+ t.timestamps
19
+ end
20
+
12
21
  create_table :fieldsets do |t|
13
22
  t.string :nkey, :null => false
14
23
  t.string :name
15
24
  t.text :description
16
- t.integer :parent_fieldset_id
17
- t.integer :order_num
18
25
 
19
26
  t.timestamps
20
27
  end
@@ -22,13 +29,11 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
22
29
 
23
30
 
24
31
  create_table :fields do |t|
25
- t.integer :fieldset_id
26
32
  t.string :name
27
33
  t.string :label, :required => true
28
34
  t.string :field_type, :required => true
29
35
  t.boolean :required, :default => false
30
36
  t.boolean :enabled, :default => true
31
- t.integer :order_num, :required => true
32
37
 
33
38
  t.timestamps
34
39
  end
@@ -58,17 +63,46 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
58
63
 
59
64
  create_table :field_records do |t|
60
65
  t.integer :fieldset_associator_id
61
- t.integer :field_id
66
+ t.integer :fieldset_child_id
62
67
  t.text :value
68
+
69
+ t.timestamps
70
+ end
71
+
72
+ create_table :dependencies do |t|
73
+ t.integer :fieldset_child_id
74
+ t.string :value
75
+ t.string :relationship
76
+ t.integer :dependency_clause_id
77
+
78
+ t.timestamps
79
+ end
80
+
81
+ create_table :dependency_clauses do |t|
82
+ t.integer :dependency_group_id
83
+
84
+ t.timestamps
85
+ end
86
+
87
+ create_table :dependency_groups do |t|
88
+ t.string :action
89
+ t.integer :fieldset_child_id
90
+
91
+ t.timestamps
63
92
  end
64
93
  end
65
94
 
66
95
  def self.down
67
96
  drop_table :fieldsets
97
+ drop_table :fieldset_children
68
98
  drop_table :fields
69
99
  drop_table :field_options
70
100
  drop_table :field_defaults
71
101
  drop_table :field_html_attributes
72
102
  drop_table :field_records
103
+
104
+ drop_table :dependencies
105
+ drop_table :dependency_clauses
106
+ drop_table :dependency_group
73
107
  end
74
108
  end
@@ -10,7 +10,29 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110727210451) do
13
+ ActiveRecord::Schema.define(:version => 20110809161724) do
14
+
15
+ create_table "dependencies", :force => true do |t|
16
+ t.integer "fieldset_child_id"
17
+ t.string "value"
18
+ t.string "relationship"
19
+ t.integer "dependency_clause_id"
20
+ t.datetime "created_at"
21
+ t.datetime "updated_at"
22
+ end
23
+
24
+ create_table "dependency_clauses", :force => true do |t|
25
+ t.integer "dependency_group_id"
26
+ t.datetime "created_at"
27
+ t.datetime "updated_at"
28
+ end
29
+
30
+ create_table "dependency_groups", :force => true do |t|
31
+ t.string "action"
32
+ t.integer "fieldset_child_id"
33
+ t.datetime "created_at"
34
+ t.datetime "updated_at"
35
+ end
14
36
 
15
37
  create_table "field_defaults", :force => true do |t|
16
38
  t.integer "field_id"
@@ -36,19 +58,19 @@ ActiveRecord::Schema.define(:version => 20110727210451) do
36
58
  end
37
59
 
38
60
  create_table "field_records", :force => true do |t|
39
- t.integer "fieldset_associator_id"
40
- t.integer "field_id"
41
- t.text "value"
61
+ t.integer "fieldset_associator_id"
62
+ t.integer "fieldset_child_id"
63
+ t.text "value"
64
+ t.datetime "created_at"
65
+ t.datetime "updated_at"
42
66
  end
43
67
 
44
68
  create_table "fields", :force => true do |t|
45
- t.integer "fieldset_id"
46
69
  t.string "name"
47
70
  t.string "label"
48
71
  t.string "field_type"
49
- t.boolean "required", :default => false
50
- t.boolean "enabled", :default => true
51
- t.integer "order_num"
72
+ t.boolean "required", :default => false
73
+ t.boolean "enabled", :default => true
52
74
  t.datetime "created_at"
53
75
  t.datetime "updated_at"
54
76
  end
@@ -62,12 +84,19 @@ ActiveRecord::Schema.define(:version => 20110727210451) do
62
84
  t.datetime "updated_at"
63
85
  end
64
86
 
87
+ create_table "fieldset_children", :force => true do |t|
88
+ t.integer "fieldset_id"
89
+ t.integer "child_id"
90
+ t.string "child_type"
91
+ t.integer "order_num"
92
+ t.datetime "created_at"
93
+ t.datetime "updated_at"
94
+ end
95
+
65
96
  create_table "fieldsets", :force => true do |t|
66
- t.string "nkey", :null => false
97
+ t.string "nkey", :null => false
67
98
  t.string "name"
68
99
  t.text "description"
69
- t.integer "parent_fieldset_id"
70
- t.integer "order_num"
71
100
  t.datetime "created_at"
72
101
  t.datetime "updated_at"
73
102
  end
@@ -10,7 +10,6 @@ Feature: Managed fields
10
10
  When I fill in "test_field" for "Label"
11
11
  And I fill in "Test field" for "Name"
12
12
  And I select "textfield" from "Field type"
13
- And I fill in "1" for "Order Number"
14
13
  And I press "Create Field"
15
14
  Then I should be on the field show page for that field
16
15
  And I should see "Successfully created a new field"
@@ -32,9 +31,15 @@ Feature: Managed fields
32
31
  Given a field exists
33
32
  And I record the data for that field
34
33
  And I am on the field index page
35
- When I follow "Destroy"
34
+ When I press "Destroy"
36
35
  Then I should not see that field listed
37
36
 
37
+ Scenario: Should not be able to destroy a field in use
38
+ Given a field exists
39
+ And the field is in use
40
+ When I go to the field index page
41
+ Then I should see "Destroy" within "del"
42
+
38
43
  # this test should be a javascript test and actually test the javascript at some point
39
44
  Scenario: Additional field links on new page
40
45
  Given a field exists
@@ -52,3 +57,13 @@ Feature: Managed fields
52
57
  And I should see "Html attribute name"
53
58
  And I should see "Html attribute value"
54
59
 
60
+ Scenario: Enabling and disabling a field
61
+ Given a field exists
62
+ When I go to the field index page
63
+ Then I should see that field listed
64
+ When I press "Disable"
65
+ Then I should be on the field index page
66
+ And I should see "Successfully updated a new field."
67
+ When I press "Enable"
68
+ Then I should be on the field index page
69
+ And I should see "Successfully updated a new field."
@@ -21,8 +21,6 @@ Feature: Managed fieldsets
21
21
  When I fill in "test_fieldset" for "Nkey"
22
22
  And I fill in "Test Fieldset" for "Name"
23
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
24
  And I press "Create Fieldset"
27
25
  Then I should be on the fieldset show page for that fieldset
28
26
  And I should see "Successfully created a new fieldset"
@@ -42,27 +40,9 @@ Feature: Managed fieldsets
42
40
  And I should see "This fieldset has been repurposed"
43
41
 
44
42
  Scenario: Destroying a fieldset
43
+ Given I am pending
45
44
  Given a parent fieldset exists
46
45
  And I record the data for that fieldset
47
46
  And I am on the fieldset index page
48
47
  When I follow "Destroy"
49
48
  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,50 @@
1
+ Feature: Managed fieldset children
2
+
3
+ Scenario: Viewing child index page from the index page
4
+ Given a parent fieldset exists
5
+ And I am on the fieldset index page
6
+ When I follow "Children"
7
+ Then I should be on the fieldset child page for that fieldset
8
+
9
+ Scenario: Viewing a one generation fieldset's index page
10
+ Given I am pending
11
+ Given a child fieldset exists
12
+ And I am on the fieldset children page for the parent fieldset
13
+ When I follow "Children"
14
+ Then I should be on the fieldset child page for that fieldset
15
+
16
+ Scenario: Viewing a fieldset's view page from the fieldset's child page
17
+ Given a child fieldset exists
18
+ And I am on the fieldset children page for the parent fieldset
19
+ When I follow "Show"
20
+ Then I should be on the child fieldset show page
21
+ And I should see the data for that fieldset
22
+
23
+ Scenario: Viewing a field's edit page from the fieldset's child page
24
+ Given a child fieldset exists
25
+ And I am on the fieldset children page for the parent fieldset
26
+ When I follow "Edit"
27
+ Then I should be on the fieldset edit page for that fieldset
28
+
29
+ Scenario: Viewing a field and a fieldset from the fieldset's child page
30
+ Given I am pending
31
+ Given a child field and fieldset exists
32
+ And I am on the fieldset children page for the parent fieldset
33
+ Then I should see the child field information
34
+ And I should see the child fieldset information
35
+
36
+ Scenario: Automatically setting fieldset when creating a new child field from the child page
37
+ Given I am pending
38
+ Given a parent fieldset exists
39
+ And I am on the fieldset child page for that fieldset
40
+ When I follow "New Child - Field"
41
+ Then I should be on the field new page
42
+ And the Parent Fieldset should be selected for "Fieldset"
43
+
44
+ Scenario: Automatically setting fieldset when creating a new child fieldset from the child page
45
+ Given I am pending
46
+ Given a parent fieldset exists
47
+ And I am on the fieldset child page for that fieldset
48
+ When I follow "New Child - Fieldset"
49
+ Then I should be on the fieldset new page
50
+ And the Parent Fieldset should be selected for "Parent fieldset"
@@ -0,0 +1,91 @@
1
+ # If these tests ever, break please delete them
2
+ # They are for demosntrating javsacript testing only
3
+ Feature: How to test with and without javascript
4
+
5
+ # If you use a javascript tag, Selenium will be loaded and used to test the page
6
+ # Normal javascript will run in a firefox browser
7
+ @javascript
8
+ Scenario: Creating a field option
9
+ Given I am on the field new page
10
+ And I should not see "remove" within "a"
11
+ When I follow "Add Field Option"
12
+ Then I should see "remove" within "a"
13
+
14
+ # If you don't use javascript, no javascript will be run because we are using a simulated browser
15
+ # In this case, clicking on the link will not do anything
16
+ Scenario: Creating a field option
17
+ Given I am on the field new page
18
+ And I should not see "remove" within "a"
19
+ When I follow "Add Field Option"
20
+ Then I should not see "remove" within "a"
21
+
22
+
23
+ # Please do not delete these tests, they are for dependencies. [hex]
24
+ # Not all of these steps are fully tested, but I should not see the instructions
25
+ # and I should see the instructions are written. They seem like they should be good, but not tested.
26
+
27
+ @javascript
28
+ Scenario: Checking textfield dependency
29
+ Given I am pending
30
+ And there is a dependency on a textfield with "I like tests"
31
+ And I am on the information forms edit page
32
+ # Not made yet
33
+ When I fill in the field with "I don't like tests"
34
+ Then I should not see the instructions
35
+ When I fill in the field with "I like tests"
36
+ Then I should see the instructions
37
+
38
+ @javascript
39
+ Scenario: Checking radio button dependency
40
+ Given I am pending
41
+ And there is a dependency on a radio
42
+ And I am on the information forms edit page
43
+ # Not made yet
44
+ When I select the radio button "Radio Button A"
45
+ Then I should not see the instructions
46
+ When I select the radio button "Radio Button B"
47
+ Then I should see the instructions
48
+
49
+ @javascript
50
+ Scenario: Checking textarea dependency
51
+ Given I am pending
52
+ And there is a dependency on a textarea with "I like tests"
53
+ And I am on the information forms edit page
54
+ # Not made yet
55
+ When I fill in the area with "I don't like tests"
56
+ Then I should not see the instructions
57
+ When I fill in the area with "I like tests"
58
+ Then I should see the instructions
59
+
60
+ @javascript
61
+ Scenario: Checking checkbox dependency
62
+ Given I am pending
63
+ And there is a dependency on a checkbox
64
+ And I am on the information forms edit page
65
+ # Not made yet
66
+ When I check the checkbox "Checkbox A"
67
+ Then I should not see the instructions
68
+ When I check the checkbox "Checkbox B"
69
+ Then I should see the instructions
70
+
71
+ @javascript
72
+ Scenario: Checking select dependency
73
+ Given I am pending
74
+ And there is a dependency on a select
75
+ And I am on the information forms edit page
76
+ # Not made yet
77
+ When I select the select option "Select Option A"
78
+ Then I should not see the instructions
79
+ When I select the select option "Select Option B"
80
+ Then I should see the instructions
81
+
82
+ @javascript
83
+ Scenario: Checking multiple select dependency
84
+ Given I am pending
85
+ And there is a dependency on a multi-select
86
+ And I am on the information forms edit page
87
+ # Not made yet
88
+ When I select the select option "Select Option A"
89
+ Then I should not see the instructions
90
+ When I select the select option "Select Option B"
91
+ Then I should see the instructions
@@ -3,11 +3,19 @@ Given /^a field exists$/ do
3
3
  :name => "Test field",
4
4
  :label => "Test field",
5
5
  :field_type => "textfield",
6
- :order_num => 1,
7
6
  :enabled => true,
8
7
  :required => true)
9
8
  end
10
9
 
10
+ Given /^the field is in use$/ do
11
+ @field = DynamicFieldsets::Field.last
12
+ if DynamicFieldsets::Fieldset.all.empty?
13
+ Given %{a fieldset exists}
14
+ end
15
+ @fsc = DynamicFieldsets::FieldsetChild.create(:child => @field, :fieldset_id => DynamicFieldsets::Fieldset.last.id)
16
+ end
17
+
18
+
11
19
  Given /^field options, defaults, and attributes exist for that field$/ do
12
20
  @field = DynamicFieldsets::Field.last
13
21
  DynamicFieldsets::FieldOption.create(:field => @field, :name => "Field option value")
@@ -17,10 +25,8 @@ end
17
25
 
18
26
  Then /^I should see that field listed$/ do
19
27
  @field = DynamicFieldsets::Field.last
20
- page.should have_content(@field.fieldset.name) if @field.fieldset
21
28
  page.should have_content(@field.name)
22
29
  page.should have_content(@field.field_type)
23
- page.should have_content(@field.order_num)
24
30
  end
25
31
 
26
32
  Then /^I should see the data for that field$/ do
@@ -28,7 +34,6 @@ Then /^I should see the data for that field$/ do
28
34
  page.should have_content(@field.name)
29
35
  page.should have_content(@field.label)
30
36
  page.should have_content(@field.field_type)
31
- page.should have_content(@field.order_num)
32
37
  page.should have_content(@field.enabled)
33
38
  page.should have_content(@field.required)
34
39
 
@@ -59,5 +64,4 @@ end
59
64
  Then /^I should not see that field listed$/ do
60
65
  page.should_not have_content(@field.name)
61
66
  page.should_not have_content(@field.field_type)
62
- page.should_not have_content(@field.order_num)
63
67
  end
@@ -1,5 +1,7 @@
1
1
  Given /^an information form exists$/ do
2
- @information_form = InformationForm.create(:name => "Test information form")
2
+ # note that we are ignoring validations for this in case the fieldset has required fields
3
+ @information_form = InformationForm.new(:name => "Test information form")
4
+ @information_form.save(:validate => false)
3
5
  end
4
6
 
5
7
  Given /^a fieldset associator exists$/ do
@@ -0,0 +1,65 @@
1
+ def create_parent_fieldset
2
+ parent_fieldset = DynamicFieldsets::Fieldset.create(
3
+ :name => "Parent Fieldset",
4
+ :nkey => "parent_fieldset",
5
+ :description => "A test parent fieldset")
6
+ return parent_fieldset
7
+ end
8
+
9
+ def create_child_fieldset(parent, order_num = 1)
10
+ child_fieldset = DynamicFieldsets::Fieldset.create(
11
+ :name => "Child Fieldset",
12
+ :nkey => "child_fieldset",
13
+ :description => "A test child fieldset")
14
+ DynamicFieldsets::FieldsetChild.create(:fieldset => parent, :child => child_fieldset, :order_num => order_num)
15
+ return child_fieldset
16
+ end
17
+
18
+ def create_child_field(parent, order_num = 1)
19
+ child_field = DynamicFieldsets::Field.create(
20
+ :name => "Child Field",
21
+ :label => "Child Field",
22
+ :field_type => "textfield",
23
+ :enabled => true,
24
+ :required => true)
25
+ DynamicFieldsets::FieldsetChild.create(:fieldset => parent, :child => child_field, :order_num => order_num)
26
+ return child_field
27
+ end
28
+
29
+ Given(/^a parent fieldset exists$/) do
30
+ @parent_fieldset = create_parent_fieldset
31
+ end
32
+
33
+ Given(/^a child fieldset exists$/) do
34
+ @parent_fieldset = create_parent_fieldset
35
+ @child_fieldset = create_child_fieldset(@parent_fieldset, 1)
36
+ end
37
+
38
+ Given /^a child field exists$/ do
39
+ @parent_fieldset = create_parent_fieldset
40
+ @child_field = create_child_field(@parent_fieldset, 1)
41
+ end
42
+
43
+ Given /^a child field and fieldset exists$/ do
44
+ @parent_fieldset = create_parent_fieldset
45
+ @child_field = create_child_field(@parent_fieldset, 1)
46
+ @child_fieldset = create_child_fieldset(@parent_fieldset, 2)
47
+ end
48
+
49
+ Then(/^the Parent Fieldset should be selected for "([^"]*)"$/) do |field|
50
+ pending "this step does not make sense in the new system."
51
+ value = DynamicFieldsets::Fieldset.last.name
52
+ page.has_xpath?("//option[@selected = 'selected' and contains(string(), value)]").should be_true
53
+ end
54
+
55
+ Then /^I should see the child field information$/ do
56
+ @child_field = DynamicFieldsets::Field.last
57
+ page.should have_content(@child_field.name)
58
+ page.should have_content(@child_field.field_type)
59
+ end
60
+
61
+ Then /^I should see the child fieldset information$/ do
62
+ @child_fieldset = DynamicFieldsets::Fieldset.last
63
+ page.should have_content(@child_fieldset.name)
64
+ page.should have_content(@child_fieldset.description)
65
+ end