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,169 @@
1
+ require 'spec_helper'
2
+ include DynamicFieldsets
3
+
4
+ describe Field do
5
+ include FieldHelper
6
+
7
+ it "should respond to fieldset" do
8
+ Field.new.should respond_to :fieldset
9
+ end
10
+
11
+ it "should respond to field_options" do
12
+ Field.new.should respond_to :field_options
13
+ end
14
+
15
+ it "should respond to field_defaults" do
16
+ Field.new.should respond_to :field_defaults
17
+ end
18
+
19
+ it "should respond to field_html_attributes" do
20
+ Field.new.should respond_to :field_html_attributes
21
+ end
22
+
23
+ describe "validations" do
24
+ before(:each) do
25
+ @field = Field.new
26
+ end
27
+
28
+ it "should be valid" do
29
+ @field.attributes = valid_attributes
30
+ @field.should be_valid
31
+ end
32
+
33
+ it "should require name" do
34
+ @field.should have(1).error_on(:name)
35
+ end
36
+
37
+ it "should require label" do
38
+ @field.should have(1).error_on(:label)
39
+ end
40
+
41
+ it "should require field_type" do
42
+ @field.should have(2).error_on(:field_type)
43
+ end
44
+
45
+ it "should require order number" do
46
+ @field.should have(1).error_on(:order_num)
47
+ end
48
+
49
+ it "should require type within the allowable types" do
50
+ @field.field_type = "unsupported_type"
51
+ @field.should have(1).error_on(:field_type)
52
+ end
53
+
54
+ it "should require type within the allowable types" do
55
+ @field.field_type = "select"
56
+ @field.should have(0).error_on(:field_type)
57
+ end
58
+
59
+
60
+ it "should require enabled true or false" do
61
+ @field.enabled = true
62
+ @field.should have(0).error_on(:enabled)
63
+ end
64
+
65
+ it "should require required true or false" do
66
+ @field.required = false
67
+ @field.should have(0).error_on(:required)
68
+ end
69
+
70
+ it "should require options if the type is one that requires options" do
71
+ @field.field_type = "select"
72
+ @field.should have(1).error_on(:field_options)
73
+ end
74
+ end
75
+
76
+ describe "options?" do
77
+ before(:each) do
78
+ @field = Field.new
79
+ end
80
+
81
+ it "should return true if the field type requires options" do
82
+ @field.field_type = "select"
83
+ @field.options?.should be_true
84
+ end
85
+
86
+ it "should return false if the field does not have options" do
87
+ @field.field_type = "textfield"
88
+ @field.options?.should be_false
89
+ end
90
+ end
91
+
92
+ describe "options" do
93
+ it "should return options from the field options table if enabled" do
94
+ field = Field.new
95
+ field_option = mock_model(DynamicFieldsets::FieldOption)
96
+ field_option.stub!(:enabled).and_return(true)
97
+ field.should_receive(:field_options).and_return([field_option])
98
+ field.options.should include field_option
99
+ end
100
+ it "should not return disabled options from the field options table" do
101
+ field = Field.new
102
+ field_option = mock_model(DynamicFieldsets::FieldOption)
103
+ field_option.stub!(:enabled).and_return(false)
104
+ field.should_receive(:field_options).and_return([field_option])
105
+ field.options.should_not include field_option
106
+ end
107
+ end
108
+
109
+ describe "has_defaults?" do
110
+ before(:each) do
111
+ @field = Field.new
112
+ end
113
+
114
+ it "should return true if the field default has a value" do
115
+ @field.should_receive(:field_defaults).and_return(["default value"])
116
+ @field.has_defaults?.should be_true
117
+ end
118
+ it "should return false if the field default has no values" do
119
+ @field.should_receive(:field_defaults).and_return([])
120
+ @field.has_defaults?.should be_false
121
+ end
122
+ end
123
+
124
+ describe "default" do
125
+ before(:each) do
126
+ @field = Field.new
127
+ end
128
+
129
+ it "should return a string if the type does not support multiple options" do
130
+ @field.stub!(:options?).and_return(false)
131
+ @field.should_receive(:field_defaults).and_return(["default value"])
132
+ @field.default.should == "default value"
133
+ end
134
+
135
+ it "should return nil if the type supports multiple options" do
136
+ @field.stub!(:options?).and_return(true)
137
+ @field.default.should be_nil
138
+ end
139
+ end
140
+
141
+ describe "defaults" do
142
+ before(:each) do
143
+ @field = Field.new
144
+ end
145
+
146
+ it "should return an array if the type supports multiple options" do
147
+ @field.stub!(:options?).and_return(true)
148
+ @field.should_receive(:field_defaults).and_return(["default value"])
149
+ @field.defaults.should == ["default value"]
150
+ end
151
+
152
+ it "should return nil if the type does not support multiple options" do
153
+ @field.stub!(:options?).and_return(false)
154
+ @field.defaults.should be_nil
155
+ end
156
+ end
157
+
158
+ describe "field_types method" do
159
+ it "should return an array" do
160
+ Field.field_types.should be_a_kind_of Array
161
+ end
162
+ end
163
+
164
+ describe "option_field_types method" do
165
+ it "should return an array" do
166
+ Field.option_field_types.should be_a_kind_of Array
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+ include DynamicFieldsets
3
+
4
+ describe FieldsetAssociator do
5
+ include FieldsetAssociatorHelper
6
+
7
+ it "should respond to fieldset" do
8
+ FieldsetAssociator.new.should respond_to :fieldset
9
+ end
10
+
11
+ it "should respond to field_records" do
12
+ FieldsetAssociator.new.should respond_to :field_records
13
+ end
14
+
15
+ describe "validations" do
16
+ before(:each) do
17
+ @fsa = FieldsetAssociator.new
18
+ end
19
+
20
+ it "should be valid" do
21
+ @fsa.attributes = valid_attributes
22
+ @fsa.should be_valid
23
+ end
24
+
25
+ it "should require a fieldset" do
26
+ @fsa.should have(1).error_on(:fieldset_id)
27
+ end
28
+
29
+ it "should require a field model id" do
30
+ @fsa.should have(1).error_on(:fieldset_model_id)
31
+ end
32
+
33
+ it "should require a field model type" do
34
+ @fsa.should have(1).error_on(:fieldset_model_type)
35
+ end
36
+
37
+ it "should require a field model name" do
38
+ @fsa.should have(1).error_on(:fieldset_model_name)
39
+ end
40
+
41
+ it "should error require a unique field model, field model name pair" do
42
+ @fsa.attributes = valid_attributes
43
+ @fsa.save
44
+ fsa2 = FieldsetAssociator.new
45
+ fsa2.should have(1).error_on(:fieldset_model_name)
46
+ end
47
+ end
48
+
49
+ describe "find_by_fieldset_model_parameters" do
50
+ before(:each) do
51
+ @fieldset = mock_model(Fieldset)
52
+ @fieldset.stub!(:nkey).and_return(":hire_form")
53
+ @fieldset.stub!(:id).and_return(1)
54
+ @fsa = FieldsetAssociator.create(valid_attributes)
55
+
56
+ @fieldset_model_attributes = valid_attributes
57
+ @fieldset_model_attributes[:fieldset] = :hire_form
58
+ end
59
+
60
+ it "should respond to find_by_fieldset_model_parameters" do
61
+ FieldsetAssociator.should respond_to :find_by_fieldset_model_parameters
62
+ end
63
+
64
+ it "should call Fieldset find_by_nkey" do
65
+ Fieldset.should_receive(:find_by_nkey).and_return(@fieldset)
66
+ FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes)
67
+ end
68
+
69
+ it "should return the correct fieldset associator" do
70
+ Fieldset.stub!(:find_by_nkey).and_return(@fieldset)
71
+ # this is a fun hack because of all the fsas being made during tests
72
+ FieldsetAssociator.find_by_fieldset_model_parameters(@fieldset_model_attributes).should include @fsa
73
+ end
74
+ end
75
+
76
+ describe "field_values method" do
77
+ before(:each) do
78
+ @fsa = FieldsetAssociator.new
79
+
80
+ @field = mock_model(DynamicFieldsets::Field)
81
+ @field.stub!(:id).and_return(37)
82
+
83
+ @field_record = mock_model(DynamicFieldsets::FieldRecord)
84
+ @field_record.stub!(:field).and_return(@field)
85
+ @field_record.stub!(:value).and_return("forty two")
86
+ @field_record.stub!(:id).and_return(42)
87
+
88
+ @fsa.stub!(:field_records).and_return([@field_record, @field_record])
89
+ end
90
+
91
+ it "should return a hash" do
92
+ @field.stub!(:field_type).and_return("")
93
+ @fsa.field_values.should be_a_kind_of Hash
94
+ end
95
+
96
+ it "should call field_records" do
97
+ @fsa.should_receive(:field_records).and_return([])
98
+ @fsa.field_values
99
+ end
100
+
101
+ # I am aware these two tests aren't really realistic because ids should be different
102
+ # Results should be consistent with these when ids are different
103
+ it "should return multiple select values as an array of ids" do
104
+ @field.stub!(:field_type).and_return("multiple_select")
105
+ @fsa.field_values.should == { 37 => [42, 42] }
106
+ end
107
+
108
+ it "should return checkboxes values as an array of ids" do
109
+ @field.stub!(:field_type).and_return("checkbox")
110
+ @fsa.field_values.should == { 37 => [42, 42] }
111
+ end
112
+
113
+ it "should return select values as an id" do
114
+ @field.stub!(:field_type).and_return("select")
115
+ @fsa.field_values.should == { 37 => 42 }
116
+ end
117
+
118
+ it "should return radio values as an id" do
119
+ @field.stub!(:field_type).and_return("radio")
120
+ @fsa.field_values.should == { 37 => 42 }
121
+ end
122
+
123
+ it "should return all other field types as strings" do
124
+ @field.stub!(:field_type).and_return("text")
125
+ @fsa.field_values.should == { 37 => "forty two" }
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,169 @@
1
+ require 'spec_helper'
2
+ include DynamicFieldsets
3
+
4
+ describe Fieldset do
5
+ include FieldsetHelper
6
+
7
+ it "should respond to fields" do
8
+ fieldset = Fieldset.new
9
+ fieldset.should respond_to :fields
10
+ end
11
+
12
+ it "should respond to parent_fieldset" do
13
+ fieldset = Fieldset.new
14
+ fieldset.should respond_to :parent_fieldset
15
+ end
16
+
17
+ it "should respond to child_fieldsets" do
18
+ fieldset = Fieldset.new
19
+ fieldset.should respond_to :child_fieldsets
20
+ end
21
+
22
+ describe "validations" do
23
+ before(:each) do
24
+ @fieldset = Fieldset.new
25
+ end
26
+
27
+ it "should be valid as a top level fieldset" do
28
+ @fieldset.attributes = valid_root_attributes
29
+ @fieldset.nkey = "top_level_nkey"
30
+ @fieldset.should be_valid
31
+ end
32
+
33
+ it "should be valid as a child fieldset" do
34
+ @fieldset.attributes = valid_child_attributes
35
+ @fieldset.nkey = "child_level_nkey"
36
+ @fieldset.should be_valid
37
+ end
38
+
39
+ it "should require a name" do
40
+ @fieldset.should have(1).error_on(:name)
41
+ end
42
+
43
+ it "should require a description" do
44
+ @fieldset.should have(1).error_on(:description)
45
+ end
46
+
47
+ it "should require an nkey" do # permalink
48
+ @fieldset.should have(1).error_on(:nkey)
49
+ end
50
+
51
+ it "should require a unique nkey" do
52
+ Fieldset.create(valid_root_attributes)
53
+ @fieldset.attributes = valid_root_attributes
54
+ @fieldset.should have(1).error_on(:nkey)
55
+ end
56
+
57
+ it "should not require an order number if there is no parent fieldset" do
58
+ @fieldset.should have(0).error_on(:order_num)
59
+ end
60
+
61
+ it "should require an order number if there is a parent fieldset" do
62
+ @fieldset.parent_fieldset = Fieldset.new
63
+ @fieldset.should have(1).error_on(:order_num)
64
+ end
65
+
66
+ it "should not allow a parent fieldset when it would create a cycle" do
67
+ fieldset1 = Fieldset.new(:nkey => "fieldset1")
68
+ fieldset2 = Fieldset.new(:parent_fieldset => fieldset1, :nkey => "fieldset2")
69
+ fieldset3 = Fieldset.new(:parent_fieldset => fieldset2, :nkey => "fieldset3")
70
+ fieldset1.parent_fieldset = fieldset3
71
+
72
+ fieldset1.should have(1).error_on(:parent_fieldset)
73
+ end
74
+ end
75
+
76
+ describe "roots scope" do
77
+ before(:each) do
78
+ @root_fieldset = Fieldset.new( valid_root_attributes )
79
+ @root_fieldset.save
80
+
81
+ @child_fieldset = Fieldset.new( valid_child_attributes )
82
+ @child_fieldset.save
83
+ end
84
+
85
+ it "should respond to roots scope" do
86
+ Fieldset.should respond_to :roots
87
+ end
88
+
89
+ it "should return fieldsets with no parent fieldset" do
90
+ roots = Fieldset.roots
91
+ roots.select{ |f| f.parent_fieldset.nil? }.should have(1).fieldset
92
+ end
93
+
94
+ it "should not return fieldsets with a parent fieldset" do
95
+ roots = Fieldset.roots
96
+ roots.select{ |f| !f.parent_fieldset.nil? }.should have(0).fieldset
97
+ end
98
+ end
99
+
100
+ describe "parent_fieldset_list static method" do
101
+ it "should include values for any fieldset" do
102
+ fieldset = Fieldset.new(:name => "parent_fieldset_list test", :nkey => "parent_fieldset_list_test")
103
+ fieldset.save(:validate => false)
104
+ DynamicFieldsets::Fieldset.parent_fieldset_list.should include [fieldset.name, fieldset.id]
105
+ end
106
+ end
107
+
108
+ describe "children method" do
109
+ before(:each) do
110
+ @root_fieldset = Fieldset.new( valid_root_attributes )
111
+
112
+ @child_fieldset = mock_model Fieldset
113
+ @child_fieldset.stub!(:id).and_return 2
114
+ @child_fieldset.stub!(:order_num).and_return 1
115
+ @child_fieldset.stub!(:name).and_return
116
+
117
+ @field1 = mock_model Field
118
+ @field1.stub!(:id).and_return 1
119
+ @field1.stub!(:order_num).and_return 2
120
+ @field1.stub!(:name).and_return 'z-field'
121
+ @field1.stub!(:enabled).and_return true
122
+
123
+ @field2 = mock_model Field
124
+ @field2.stub!(:id).and_return 2
125
+ @field2.stub!(:order_num).and_return 2
126
+ @field2.stub!(:name).and_return 'a-field'
127
+ @field2.stub!(:enabled).and_return true
128
+
129
+ end
130
+
131
+ it "should respond to children" do
132
+ @root_fieldset.should respond_to :children
133
+ end
134
+
135
+ it "should call fields and return them" do
136
+ @root_fieldset.should_receive(:fields).and_return [@field1]
137
+ @root_fieldset.children.should include @field1
138
+ end
139
+
140
+ it "should call child_fieldsets and return them" do
141
+ @root_fieldset.should_receive(:child_fieldsets).and_return [@child_fieldset]
142
+ @root_fieldset.children.should include @child_fieldset
143
+ end
144
+
145
+ it "should return a mixture of fieldsets and fields" do
146
+ @root_fieldset.stub!(:fields).and_return [@field1]
147
+ @root_fieldset.stub!(:child_fieldsets).and_return [@child_fieldset]
148
+ children = @root_fieldset.children
149
+ children.should include @field1
150
+ children.should include @child_fieldset
151
+ end
152
+
153
+ it "should maintain the order of the children regardless of class" do
154
+ @root_fieldset.stub!(:fields).and_return [@field1]
155
+ @root_fieldset.stub!(:child_fieldsets).and_return [@child_fieldset]
156
+ children = @root_fieldset.children
157
+ children.first.should == @child_fieldset
158
+ children.last.should == @field1
159
+ end
160
+
161
+ it "should handle duplicate order numbers by alphabetical order of name" do
162
+ @root_fieldset.stub!(:fields).and_return [@field1, @field2]
163
+ children = @root_fieldset.children
164
+ children.first.should == @field2
165
+ children.last.should == @field1
166
+ end
167
+ end
168
+
169
+ end
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="ActsAsMultipartForm" tests="1" time="0.04001929" failures="0" errors="0" skipped="0">
3
+ <testcase name="ActsAsMultipartForm should be valid" time="0.039701244">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,47 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="MultipartForm::InProgressForm validations" tests="5" time="0.00780956" failures="0" errors="5" skipped="0">
3
+ <testcase name="MultipartForm::InProgressForm validations should be valid" time="0.001769442">
4
+ <failure type="ActiveRecord::StatementInvalid" message="Could not find table 'in_progress_forms'">
5
+ Could not find table 'in_progress_forms' (ActiveRecord::StatementInvalid)
6
+ ActiveRecord::StatementInvalid:
7
+ Could not find table 'in_progress_forms'
8
+ ./spec/in_progress_form_spec.rb:6:in `new'
9
+ ./spec/in_progress_form_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;' </failure>
10
+ </testcase>
11
+ <testcase name="MultipartForm::InProgressForm validations should require a form subject" time="0.00119303">
12
+ <failure type="ActiveRecord::StatementInvalid" message="Could not find table 'in_progress_forms'">
13
+ Could not find table 'in_progress_forms' (ActiveRecord::StatementInvalid)
14
+ ActiveRecord::StatementInvalid:
15
+ Could not find table 'in_progress_forms'
16
+ ./spec/in_progress_form_spec.rb:6:in `new'
17
+ ./spec/in_progress_form_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;' </failure>
18
+ </testcase>
19
+ <testcase name="MultipartForm::InProgressForm validations should require a form name" time="0.001504453">
20
+ <failure type="ActiveRecord::StatementInvalid" message="Could not find table 'in_progress_forms'">
21
+ Could not find table 'in_progress_forms' (ActiveRecord::StatementInvalid)
22
+ ActiveRecord::StatementInvalid:
23
+ Could not find table 'in_progress_forms'
24
+ ./spec/in_progress_form_spec.rb:6:in `new'
25
+ ./spec/in_progress_form_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;' </failure>
26
+ </testcase>
27
+ <testcase name="MultipartForm::InProgressForm validations should require a last completed step" time="0.001388378">
28
+ <failure type="ActiveRecord::StatementInvalid" message="Could not find table 'in_progress_forms'">
29
+ Could not find table 'in_progress_forms' (ActiveRecord::StatementInvalid)
30
+ ActiveRecord::StatementInvalid:
31
+ Could not find table 'in_progress_forms'
32
+ ./spec/in_progress_form_spec.rb:6:in `new'
33
+ ./spec/in_progress_form_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;' </failure>
34
+ </testcase>
35
+ <testcase name="MultipartForm::InProgressForm validations should require completed" time="0.001450073">
36
+ <failure type="ActiveRecord::StatementInvalid" message="Could not find table 'in_progress_forms'">
37
+ Could not find table 'in_progress_forms' (ActiveRecord::StatementInvalid)
38
+ ActiveRecord::StatementInvalid:
39
+ Could not find table 'in_progress_forms'
40
+ ./spec/in_progress_form_spec.rb:6:in `new'
41
+ ./spec/in_progress_form_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;' </failure>
42
+ </testcase>
43
+ <system-out>
44
+ </system-out>
45
+ <system-err>
46
+ </system-err>
47
+ </testsuite>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="MultipartForm::InProgressForm" tests="0" time="0.000230508" failures="0" errors="0" skipped="0">
3
+ <system-out>
4
+ </system-out>
5
+ <system-err>
6
+ </system-err>
7
+ </testsuite>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Navigation" tests="1" time="0.004622105" failures="0" errors="0" skipped="0">
3
+ <testcase name="Navigation should be a valid app" time="0.002294373">
4
+ </testcase>
5
+ <system-out>
6
+ </system-out>
7
+ <system-err>
8
+ </system-err>
9
+ </testsuite>
@@ -0,0 +1,37 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require "ruby-debug"
5
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ require "rails/test_help"
7
+ require "rspec/rails"
8
+
9
+ ActionMailer::Base.delivery_method = :test
10
+ ActionMailer::Base.perform_deliveries = true
11
+ ActionMailer::Base.default_url_options[:host] = "test.com"
12
+
13
+ Rails.backtrace_cleaner.remove_silencers!
14
+
15
+ # Configure capybara for integration testing
16
+ require "capybara/rails"
17
+ Capybara.default_driver = :rack_test
18
+ Capybara.default_selector = :css
19
+
20
+ # Run any available migration
21
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
22
+
23
+ # Load support files
24
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
25
+
26
+ RSpec.configure do |config|
27
+ # Remove this line if you don't want RSpec's should and should_not
28
+ # methods or matchers
29
+ require 'rspec/expectations'
30
+ config.include RSpec::Matchers
31
+
32
+ # == Mock Framework
33
+ config.mock_with :rspec
34
+
35
+ # use transactions
36
+ config.use_transactional_fixtures = true
37
+ end
@@ -0,0 +1,12 @@
1
+ # Helper for the field_defaults to create valid attributes and other data used in multiple tests
2
+ module FieldDefaultHelper
3
+ # attributes for a field default
4
+ # @returns [Hash] all attributes needed to pass validations
5
+ def valid_attributes
6
+ {
7
+ :id => 1,
8
+ :field_id => 1,
9
+ :value => "Scott Sampson",
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # Helper for the field model to create valid attributes
2
+ module FieldHelper
3
+ # this has issues with not being able to set type
4
+ # I am manually setting it where it is needed to avoid problems
5
+ def valid_attributes
6
+ {
7
+ :fieldset_id => 1,
8
+ :name => "Test field name",
9
+ :label => "Test field label",
10
+ :field_type => "textfield",
11
+ :required => true,
12
+ :enabled => true,
13
+ :order_num => 1
14
+ }
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # Helper for the fieldset to create valid attributes and other data used in multiple tests
2
+ module FieldHtmlAttributeHelper
3
+ # attributes for a html attribute
4
+ # @returns [Hash] all attributes needed to pass validations
5
+ def valid_attributes
6
+ {
7
+ :id => 1,
8
+ :field_id => 1,
9
+ :attribute_name => "class",
10
+ :value => "on"
11
+ }
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ # Helper for the field_options to create valid attributes and other data used in multiple tests
2
+ module FieldOptionHelper
3
+ # attributes for a field option
4
+ # @returns [Hash] all attributes needed to pass validations
5
+ def valid_attributes
6
+ {
7
+ :id => 1,
8
+ :field_id => 1,
9
+ :name => "Supervisor",
10
+ :enabled => true
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # Helper for the field record model
2
+ module FieldRecordHelper
3
+ # attributes for the field reocrd that should pass validations
4
+ # @returns [Hash] All attributes needed to pass validations
5
+ def valid_attributes
6
+ {
7
+ :field_id => 1,
8
+ :fieldset_associator_id => 1,
9
+ :value => "forty two"
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module FieldsetAssociatorHelper
3
+
4
+ def valid_attributes
5
+ {
6
+ :fieldset_id => 1,
7
+ :fieldset_model_type => "Person",
8
+ :fieldset_model_id => 1,
9
+ :fieldset_model_name => :hire_form
10
+ }
11
+ end
12
+ end