dynamic_fieldsets 0.0.8 → 0.0.9

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.9
2
+
3
+ * Added field_records_by_field_name method to find the answers to questions by name
4
+
1
5
  == 0.0.8
2
6
 
3
7
  * Added controller and views generators
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.8
1
+ 0.0.9
@@ -76,6 +76,22 @@ module DynamicFieldsets
76
76
  return output
77
77
  end
78
78
 
79
+ # Record whose field matches the name and associator matches the current associator
80
+ #
81
+ # This will be used to get answers to questions with hard coded names
82
+ #
83
+ # @return [Array] the matching records
84
+ def field_records_by_field_name(name)
85
+ records = self.field_records.select { |record| record.fieldset_child.child.name == name }
86
+ return records
87
+
88
+ # this version uses less queries but feels less elegant
89
+ # field = DynamicFieldsets::Field.find_by_name(name)
90
+ # child = DynamicFieldsets::FieldsetChild.where(:child => field, :fieldset => self.fieldset).first
91
+ # records = DynamicFieldsets::FieldRecord.where(:child => child, :associator => self)
92
+ # return records
93
+ end
94
+
79
95
 
80
96
  # OMG COMMENT
81
97
  #
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynamic_fieldsets}
8
- s.version = "0.0.8"
8
+ s.version = "0.0.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Jeremiah Hemphill}, %q{Ethan Pemble}, %q{John Carter}]
12
- s.date = %q{2012-01-18}
12
+ s.date = %q{2012-01-19}
13
13
  s.description = %q{Dynamic fieldsets for rails controllers}
14
14
  s.email = %q{jeremiah@cloudspace.com}
15
15
  s.extra_rdoc_files = [
@@ -111,7 +111,7 @@ Gem::Specification.new do |s|
111
111
  "spec/dummy/config/locales/en.yml",
112
112
  "spec/dummy/config/routes.rb",
113
113
  "spec/dummy/db/migrate/20110727210451_create_information_forms.rb",
114
- "spec/dummy/db/migrate/20110809161724_create_dynamic_fieldsets_tables.rb",
114
+ "spec/dummy/db/migrate/20111111154935_create_dynamic_fieldsets_tables.rb",
115
115
  "spec/dummy/db/schema.rb",
116
116
  "spec/dummy/features/field.feature",
117
117
  "spec/dummy/features/fieldset.feature",
@@ -1,6 +1,6 @@
1
1
  class CreateDynamicFieldsetsTables < ActiveRecord::Migration
2
2
  def self.up
3
- create_table :fieldset_associators do |t|
3
+ create_table :dynamic_fieldsets_fieldset_associators do |t|
4
4
  t.integer :fieldset_id
5
5
  t.integer :fieldset_model_id
6
6
  t.string :fieldset_model_type
@@ -9,7 +9,7 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
9
9
  t.timestamps
10
10
  end
11
11
 
12
- create_table :fieldset_children do |t|
12
+ create_table :dynamic_fieldsets_fieldset_children do |t|
13
13
  t.integer :fieldset_id
14
14
  t.integer :child_id
15
15
  t.string :child_type
@@ -18,17 +18,17 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
18
18
  t.timestamps
19
19
  end
20
20
 
21
- create_table :fieldsets do |t|
21
+ create_table :dynamic_fieldsets_fieldsets do |t|
22
22
  t.string :nkey, :null => false
23
23
  t.string :name
24
24
  t.text :description
25
25
 
26
26
  t.timestamps
27
27
  end
28
- add_index :fieldsets, :nkey, :unique => true
28
+ add_index :dynamic_fieldsets_fieldsets, :nkey, :unique => true
29
29
 
30
30
 
31
- create_table :fields do |t|
31
+ create_table :dynamic_fieldsets_fields do |t|
32
32
  t.string :name
33
33
  t.string :label, :required => true
34
34
  t.string :field_type, :required => true
@@ -38,7 +38,7 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
38
38
  t.timestamps
39
39
  end
40
40
 
41
- create_table :field_options do |t|
41
+ create_table :dynamic_fieldsets_field_options do |t|
42
42
  t.integer :field_id
43
43
  t.string :name
44
44
  t.boolean :enabled, :default => true
@@ -46,14 +46,14 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
46
46
  t.timestamps
47
47
  end
48
48
 
49
- create_table :field_defaults do |t|
49
+ create_table :dynamic_fieldsets_field_defaults do |t|
50
50
  t.integer :field_id
51
51
  t.string :value
52
52
 
53
53
  t.timestamps
54
54
  end
55
55
 
56
- create_table :field_html_attributes do |t|
56
+ create_table :dynamic_fieldsets_field_html_attributes do |t|
57
57
  t.integer :field_id
58
58
  t.string :attribute_name, :required => true # couldn't use attribute because it is used by active record
59
59
  t.string :value, :required => true
@@ -61,7 +61,7 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
61
61
  t.timestamps
62
62
  end
63
63
 
64
- create_table :field_records do |t|
64
+ create_table :dynamic_fieldsets_field_records do |t|
65
65
  t.integer :fieldset_associator_id
66
66
  t.integer :fieldset_child_id
67
67
  t.text :value
@@ -69,7 +69,7 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
69
69
  t.timestamps
70
70
  end
71
71
 
72
- create_table :dependencies do |t|
72
+ create_table :dynamic_fieldsets_dependencies do |t|
73
73
  t.integer :fieldset_child_id
74
74
  t.string :value
75
75
  t.string :relationship
@@ -78,13 +78,13 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
78
78
  t.timestamps
79
79
  end
80
80
 
81
- create_table :dependency_clauses do |t|
81
+ create_table :dynamic_fieldsets_dependency_clauses do |t|
82
82
  t.integer :dependency_group_id
83
83
 
84
84
  t.timestamps
85
85
  end
86
86
 
87
- create_table :dependency_groups do |t|
87
+ create_table :dynamic_fieldsets_dependency_groups do |t|
88
88
  t.string :action
89
89
  t.integer :fieldset_child_id
90
90
 
@@ -93,16 +93,16 @@ class CreateDynamicFieldsetsTables < ActiveRecord::Migration
93
93
  end
94
94
 
95
95
  def self.down
96
- drop_table :fieldsets
97
- drop_table :fieldset_children
98
- drop_table :fields
99
- drop_table :field_options
100
- drop_table :field_defaults
101
- drop_table :field_html_attributes
102
- drop_table :field_records
103
-
104
- drop_table :dependencies
105
- drop_table :dependency_clauses
106
- drop_table :dependency_group
96
+ drop_table :dynamic_fieldsets_fieldsets
97
+ drop_table :dynamic_fieldsets_fieldset_children
98
+ drop_table :dynamic_fieldsets_fields
99
+ drop_table :dynamic_fieldsets_field_options
100
+ drop_table :dynamic_fieldsets_field_defaults
101
+ drop_table :dynamic_fieldsets_field_html_attributes
102
+ drop_table :dynamic_fieldsets_field_records
103
+
104
+ drop_table :dynamic_fieldsets_dependencies
105
+ drop_table :dynamic_fieldsets_dependency_clauses
106
+ drop_table :dynamic_fieldsets_dependency_group
107
107
  end
108
108
  end
@@ -10,9 +10,9 @@
10
10
  #
11
11
  # It's strongly recommended to check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(:version => 20110809161724) do
13
+ ActiveRecord::Schema.define(:version => 20111111154935) do
14
14
 
15
- create_table "dependencies", :force => true do |t|
15
+ create_table "dynamic_fieldsets_dependencies", :force => true do |t|
16
16
  t.integer "fieldset_child_id"
17
17
  t.string "value"
18
18
  t.string "relationship"
@@ -21,27 +21,27 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
21
21
  t.datetime "updated_at"
22
22
  end
23
23
 
24
- create_table "dependency_clauses", :force => true do |t|
24
+ create_table "dynamic_fieldsets_dependency_clauses", :force => true do |t|
25
25
  t.integer "dependency_group_id"
26
26
  t.datetime "created_at"
27
27
  t.datetime "updated_at"
28
28
  end
29
29
 
30
- create_table "dependency_groups", :force => true do |t|
30
+ create_table "dynamic_fieldsets_dependency_groups", :force => true do |t|
31
31
  t.string "action"
32
32
  t.integer "fieldset_child_id"
33
33
  t.datetime "created_at"
34
34
  t.datetime "updated_at"
35
35
  end
36
36
 
37
- create_table "field_defaults", :force => true do |t|
37
+ create_table "dynamic_fieldsets_field_defaults", :force => true do |t|
38
38
  t.integer "field_id"
39
39
  t.string "value"
40
40
  t.datetime "created_at"
41
41
  t.datetime "updated_at"
42
42
  end
43
43
 
44
- create_table "field_html_attributes", :force => true do |t|
44
+ create_table "dynamic_fieldsets_field_html_attributes", :force => true do |t|
45
45
  t.integer "field_id"
46
46
  t.string "attribute_name"
47
47
  t.string "value"
@@ -49,7 +49,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
49
49
  t.datetime "updated_at"
50
50
  end
51
51
 
52
- create_table "field_options", :force => true do |t|
52
+ create_table "dynamic_fieldsets_field_options", :force => true do |t|
53
53
  t.integer "field_id"
54
54
  t.string "name"
55
55
  t.boolean "enabled", :default => true
@@ -57,7 +57,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
57
57
  t.datetime "updated_at"
58
58
  end
59
59
 
60
- create_table "field_records", :force => true do |t|
60
+ create_table "dynamic_fieldsets_field_records", :force => true do |t|
61
61
  t.integer "fieldset_associator_id"
62
62
  t.integer "fieldset_child_id"
63
63
  t.text "value"
@@ -65,7 +65,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
65
65
  t.datetime "updated_at"
66
66
  end
67
67
 
68
- create_table "fields", :force => true do |t|
68
+ create_table "dynamic_fieldsets_fields", :force => true do |t|
69
69
  t.string "name"
70
70
  t.string "label"
71
71
  t.string "field_type"
@@ -75,7 +75,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
75
75
  t.datetime "updated_at"
76
76
  end
77
77
 
78
- create_table "fieldset_associators", :force => true do |t|
78
+ create_table "dynamic_fieldsets_fieldset_associators", :force => true do |t|
79
79
  t.integer "fieldset_id"
80
80
  t.integer "fieldset_model_id"
81
81
  t.string "fieldset_model_type"
@@ -84,7 +84,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
84
84
  t.datetime "updated_at"
85
85
  end
86
86
 
87
- create_table "fieldset_children", :force => true do |t|
87
+ create_table "dynamic_fieldsets_fieldset_children", :force => true do |t|
88
88
  t.integer "fieldset_id"
89
89
  t.integer "child_id"
90
90
  t.string "child_type"
@@ -93,7 +93,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
93
93
  t.datetime "updated_at"
94
94
  end
95
95
 
96
- create_table "fieldsets", :force => true do |t|
96
+ create_table "dynamic_fieldsets_fieldsets", :force => true do |t|
97
97
  t.string "nkey", :null => false
98
98
  t.string "name"
99
99
  t.text "description"
@@ -101,7 +101,7 @@ ActiveRecord::Schema.define(:version => 20110809161724) do
101
101
  t.datetime "updated_at"
102
102
  end
103
103
 
104
- add_index "fieldsets", ["nkey"], :name => "index_fieldsets_on_nkey", :unique => true
104
+ add_index "dynamic_fieldsets_fieldsets", ["nkey"], :name => "index_dynamic_fieldsets_fieldsets_on_nkey", :unique => true
105
105
 
106
106
  create_table "information_forms", :force => true do |t|
107
107
  t.string "name"
@@ -128,6 +128,28 @@ describe FieldsetAssociator do
128
128
  end
129
129
  end
130
130
 
131
+ # these tests seem silly when they don't hit the database
132
+ describe "field_records_by_field_name method" do
133
+ before(:each) do
134
+ @fieldset = Fieldset.new
135
+ @field = Field.new(:name => "test_field")
136
+ @child = FieldsetChild.new(:fieldset => @fieldset, :child => @field)
137
+
138
+ @fsa = FieldsetAssociator.new(:fieldset => @fieldset)
139
+ @record = FieldRecord.new(:fieldset_child => @child)
140
+
141
+ @fsa.stub!(:field_records).and_return([@record])
142
+ end
143
+
144
+ it "should return a field record if it matches the input" do
145
+ @fsa.field_records_by_field_name("test_field").should include @record
146
+ end
147
+
148
+ it "should not return field records that do not match the input" do
149
+ @fsa.field_records_by_field_name("a_different_field").should_not include @record
150
+ end
151
+ end
152
+
131
153
  describe "dependency_child_hash and look_for_dependents" do
132
154
  before(:each) do
133
155
  @fsa = FieldsetAssociator.new
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dynamic_fieldsets
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeremiah Hemphill
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-01-18 00:00:00 Z
15
+ date: 2012-01-19 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -283,7 +283,7 @@ files:
283
283
  - spec/dummy/config/locales/en.yml
284
284
  - spec/dummy/config/routes.rb
285
285
  - spec/dummy/db/migrate/20110727210451_create_information_forms.rb
286
- - spec/dummy/db/migrate/20110809161724_create_dynamic_fieldsets_tables.rb
286
+ - spec/dummy/db/migrate/20111111154935_create_dynamic_fieldsets_tables.rb
287
287
  - spec/dummy/db/schema.rb
288
288
  - spec/dummy/features/field.feature
289
289
  - spec/dummy/features/fieldset.feature
@@ -351,7 +351,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
351
  requirements:
352
352
  - - ">="
353
353
  - !ruby/object:Gem::Version
354
- hash: -2041176636100480395
354
+ hash: -2492720374457276068
355
355
  segments:
356
356
  - 0
357
357
  version: "0"