dynamic_fieldsets 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.10
2
+
3
+ * Fixed an issue where models using Dynamic Fieldsets could not be created without the fieldset information
4
+ * Removed a line break from the default textarea introduced by the html processing in the hlper
5
+
1
6
  == 0.0.9
2
7
 
3
8
  * Added field_records_by_field_name method to find the answers to questions by name
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -117,9 +117,9 @@ module DynamicFieldsetsHelper
117
117
  tag = "<textarea"
118
118
  attrs.each{ |att,val| tag += " #{att}=\"#{val}\"" }
119
119
  tag += ">"
120
+ tag += populate( field, values )
121
+ tag += "</textarea>"
120
122
  field_markup.push tag
121
- field_markup.push populate( field, values )
122
- field_markup.push "</textarea>"
123
123
 
124
124
  when :date
125
125
  date_options = { start_year: Time.now.year - 70 }
@@ -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.9"
8
+ s.version = "0.0.10"
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-19}
12
+ s.date = %q{2012-01-25}
13
13
  s.description = %q{Dynamic fieldsets for rails controllers}
14
14
  s.email = %q{jeremiah@cloudspace.com}
15
15
  s.extra_rdoc_files = [
@@ -52,16 +52,23 @@ module DynamicFieldsets
52
52
  end
53
53
 
54
54
  # Iterates over the fieldset associator's children and adds errors
55
+ #
56
+ # Will not validate fieldsets that are missing from the dynamic_fieldsets_values hash
57
+ # This means that if the data is not provided by the controller, no checks will be run
55
58
  def run_dynamic_fieldset_validations!
56
59
  # for each fsa
57
60
  self.dynamic_fieldsets.keys.each do |key|
58
61
  fsa = self.fieldset_associator(key)
59
- run_fieldset_child_validations!(fsa.id, fsa.fieldset)
62
+ fsa_tag_id = "fsa-" + fsa.id.to_s
63
+
64
+ if !self.dynamic_fieldset_values.nil? && self.dynamic_fieldset_values.has_key?(fsa_tag_id)
65
+ run_fieldset_child_validations!(fsa.id, fsa.fieldset)
66
+ end
60
67
  end
61
68
  end
62
69
 
63
70
  # Checks if a fieldset child is required and adds an error if it's value is blank
64
- # Adds errors to the sel.errors array, does not return them
71
+ # Adds errors to the self.errors array, does not return them
65
72
  #
66
73
  # @param [Integer] fsa_id The id for the fieldset associator the child belongs to
67
74
  # @param [Field or Fieldset] child The child of the fieldset associator
@@ -75,8 +82,8 @@ module DynamicFieldsets
75
82
  # if a child, check if the params value is set, check if it is required, check if it satisfies condition
76
83
  fsa_tag_id = "fsa-" + fsa_id.to_s
77
84
  field_tag_id = "field-" + child.id.to_s
78
- if !self.dynamic_fieldset_values.has_key?(fsa_tag_id) || !self.dynamic_fieldset_values[fsa_tag_id].has_key?(field_tag_id)
79
- self.errors.add(:base, child.label + " is required and the input is missing")
85
+ if !self.dynamic_fieldset_values[fsa_tag_id].has_key?(field_tag_id)
86
+ self.errors.add(:base, child.label + " is missing from the form data")
80
87
  else
81
88
  # get the value
82
89
  value = self.dynamic_fieldset_values[fsa_tag_id][field_tag_id]
@@ -91,7 +98,9 @@ module DynamicFieldsets
91
98
  end
92
99
  end
93
100
 
94
- # Stores the dynamic fieldset values
101
+ # Stores data from the controller into the dynamic_fieldset_values instance variable
102
+ #
103
+ # @param [Hash] params The parameters from the controller that include fsa tags
95
104
  def set_fieldset_values( params )
96
105
  values = params.select{ |key| key.match(/^fsa-/) }
97
106
  values.keys.each do |key|
@@ -101,6 +110,11 @@ module DynamicFieldsets
101
110
  end
102
111
 
103
112
  # This turns your date fields into a MySQL-happy single format. This modifies the hash.
113
+ #
114
+ # This method may cause bugs for servers not using UTC time because of the way rails deals with
115
+ # time conversions. If the query receives a string instead of a time object, time zone information
116
+ # may be saved incorrectly. (1-25-2012)
117
+ #
104
118
  # @param [Hash] post The post parameters that include date fields like date(1i), date(2i), ...
105
119
  # @return [Hash] The modified hash containing one key-pair value in YYYY-MM-DD[ hh:mm] format.
106
120
  def set_date_to_mysql( post )
@@ -1,3 +1,5 @@
1
1
  class InformationForm < ActiveRecord::Base
2
+ # important note: for this to work, there needs to have a fieldset with an nkey of "first" in the db
3
+ # so that DynamicFieldsets::Fieldset.find_by_nkey("first") returns a fieldset
2
4
  acts_as_dynamic_fieldset :child_form => {:fieldset => :first}
3
5
  end
@@ -62,6 +62,7 @@ describe DynamicFieldsetsInModel do
62
62
  end
63
63
 
64
64
  it "should call run_fieldset_child_validations for each key" do
65
+ @information_form.stub!(:dynamic_fieldset_values).and_return({"fsa-1" => {}})
65
66
  @information_form.should_receive(:run_fieldset_child_validations!)
66
67
  @information_form.run_dynamic_fieldset_validations!
67
68
  end
@@ -91,7 +92,7 @@ describe DynamicFieldsetsInModel do
91
92
  values = { "fsa-1" => { "field-4200"=>"" } }
92
93
  @information_form.stub!(:dynamic_fieldset_values).and_return(values)
93
94
  @information_form.run_fieldset_child_validations!(@fsa.id, @field)
94
- @information_form.errors[:base].should include "Test Field is required and the input is missing"
95
+ @information_form.errors[:base].should include "Test Field is missing from the form data"
95
96
  end
96
97
 
97
98
  it "should add an error if the field is required, the value is an array, and the value is empty" do
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.9
5
+ version: 0.0.10
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-19 00:00:00 Z
15
+ date: 2012-01-25 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -351,7 +351,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
351
  requirements:
352
352
  - - ">="
353
353
  - !ruby/object:Gem::Version
354
- hash: -2492720374457276068
354
+ hash: -1922917679847302797
355
355
  segments:
356
356
  - 0
357
357
  version: "0"