datts_right 0.0.25 → 0.0.26
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/Gemfile.lock +2 -1
 - data/VERSION +1 -1
 - data/datts_right.gemspec +2 -2
 - data/lib/datts_right/instance_methods.rb +6 -5
 - data/spec/datts_right/add_definitions_spec.rb +11 -4
 - metadata +4 -4
 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.0.26
         
     | 
    
        data/datts_right.gemspec
    CHANGED
    
    | 
         @@ -5,11 +5,11 @@ 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       7 
7 
     | 
    
         
             
              s.name = %q{datts_right}
         
     | 
| 
       8 
     | 
    
         
            -
              s.version = "0.0. 
     | 
| 
      
 8 
     | 
    
         
            +
              s.version = "0.0.26"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         
     | 
| 
       11 
11 
     | 
    
         
             
              s.authors = ["Ramon Tayag"]
         
     | 
| 
       12 
     | 
    
         
            -
              s.date = %q{2011-04- 
     | 
| 
      
 12 
     | 
    
         
            +
              s.date = %q{2011-04-27}
         
     | 
| 
       13 
13 
     | 
    
         
             
              s.description = %q{Creates a separate table that saves all your dynamic attributes.}
         
     | 
| 
       14 
14 
     | 
    
         
             
              s.email = %q{ramon@tayag.net}
         
     | 
| 
       15 
15 
     | 
    
         
             
              s.extra_rdoc_files = [
         
     | 
| 
         @@ -118,13 +118,14 @@ module DattsRight 
     | 
|
| 
       118 
118 
     | 
    
         | 
| 
       119 
119 
     | 
    
         
             
                def create_dynamic_attribute_definition_if_needed
         
     | 
| 
       120 
120 
     | 
    
         
             
                  if dynamic_attributes_options[:definition]
         
     | 
| 
       121 
     | 
    
         
            -
                    DynamicAttributeDefinition.create :attribute_defineable_id => self.id, :attribute_defineable_type => self.class.name
         
     | 
| 
      
 121 
     | 
    
         
            +
                    DynamicAttributeDefinition.create :attribute_defineable_id => self.id, :attribute_defineable_type => self.class.name, :definition => {}
         
     | 
| 
       122 
122 
     | 
    
         
             
                  end
         
     | 
| 
       123 
123 
     | 
    
         
             
                end
         
     | 
| 
       124 
124 
     | 
    
         | 
| 
       125 
125 
     | 
    
         
             
                def add_definition(key, value)
         
     | 
| 
       126 
126 
     | 
    
         
             
                  if key
         
     | 
| 
       127 
127 
     | 
    
         
             
                    key = key.to_sym
         
     | 
| 
      
 128 
     | 
    
         
            +
                    #puts "add_definition(:#{key}, #{value.inspect}). current definition: #{definition.nil?}"
         
     | 
| 
       128 
129 
     | 
    
         
             
                    if dynamic_attributes_options[:definition]
         
     | 
| 
       129 
130 
     | 
    
         
             
                      if definition[key]
         
     | 
| 
       130 
131 
     | 
    
         
             
                        raise AlreadyDefined, "#{key} is already defined"
         
     | 
| 
         @@ -153,14 +154,14 @@ module DattsRight 
     | 
|
| 
       153 
154 
     | 
    
         
             
                        #puts "#{v} IS a hash"
         
     | 
| 
       154 
155 
     | 
    
         
             
                        add_definition k, v
         
     | 
| 
       155 
156 
     | 
    
         
             
                      else # v is not a hash; item is like {"name"=>"A key", "attr_key"=>"a_key"}, {"name"=>"B key", "attr_key"=>"b_key"}
         
     | 
| 
       156 
     | 
    
         
            -
                        # 
     | 
| 
       157 
     | 
    
         
            -
                        # 
     | 
| 
       158 
     | 
    
         
            -
                        item.symbolize_keys! # {:name=>"A key", :description=>"asd", :attr_key=>"a_key"}
         
     | 
| 
      
 157 
     | 
    
         
            +
                        # Sometimes the item is a ActiveRecord::HashWithIndifferentAccess, which doesn't have the method symbolize_keys!, so we do it manually
         
     | 
| 
      
 158 
     | 
    
         
            +
                        #item = item.symbolize_keys # {:name=>"A key", :description=>"asd", :attr_key=>"a_key"}
         
     | 
| 
       159 
159 
     | 
    
         
             
                        #puts "item is symbolized: #{item.inspect}"
         
     | 
| 
       160 
     | 
    
         
            -
                        attr_key = item.delete( 
     | 
| 
      
 160 
     | 
    
         
            +
                        attr_key = item.delete("attr_key")
         
     | 
| 
       161 
161 
     | 
    
         
             
                        #puts "This is the attr_key: #{attr_key}"
         
     | 
| 
       162 
162 
     | 
    
         
             
                        if attr_key # we only want to work on it if there's an attr_key
         
     | 
| 
       163 
163 
     | 
    
         
             
                          attr_key = attr_key.to_sym
         
     | 
| 
      
 164 
     | 
    
         
            +
                          #puts "Adding: :#{attr_key}, #{item.inspect}"
         
     | 
| 
       164 
165 
     | 
    
         
             
                          add_definition(attr_key, item)
         
     | 
| 
       165 
166 
     | 
    
         
             
                        end
         
     | 
| 
       166 
167 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -15,15 +15,22 @@ describe DattsRight, ".add_definitions(hash)" do 
     | 
|
| 
       15 
15 
     | 
    
         
             
              it "should accept 'flat' hashes in an array (straight from a form)" do
         
     | 
| 
       16 
16 
     | 
    
         
             
                # [{"name"=>"A key", "description"=>"asd", "attr_key"=>"a_key"}, {"name"=>"A key", "description"=>"asd", "attr_key"=>"b_key"}]
         
     | 
| 
       17 
17 
     | 
    
         
             
                c = Category.create
         
     | 
| 
       18 
     | 
    
         
            -
                c.should_receive(:add_definition).with(:a_key, { 
     | 
| 
       19 
     | 
    
         
            -
                c.should_receive(:add_definition).with(:b_key, { 
     | 
| 
      
 18 
     | 
    
         
            +
                c.should_receive(:add_definition).with(:a_key, {"name"=>"A key"})
         
     | 
| 
      
 19 
     | 
    
         
            +
                c.should_receive(:add_definition).with(:b_key, {"name"=>"B key"})
         
     | 
| 
       20 
20 
     | 
    
         
             
                c.add_definitions({"name"=>"A key", "attr_key"=>"a_key"}, {"name"=>"B key", "attr_key"=>"b_key"})
         
     | 
| 
       21 
21 
     | 
    
         
             
                c = Category.create
         
     | 
| 
       22 
     | 
    
         
            -
                c.should_receive(:add_definition).with(:a_key, { 
     | 
| 
       23 
     | 
    
         
            -
                c.should_receive(:add_definition).with(:b_key, { 
     | 
| 
      
 22 
     | 
    
         
            +
                c.should_receive(:add_definition).with(:a_key, {"name"=>"A key"})
         
     | 
| 
      
 23 
     | 
    
         
            +
                c.should_receive(:add_definition).with(:b_key, {"name"=>"B key"})
         
     | 
| 
       24 
24 
     | 
    
         
             
                c.add_definitions([{"name"=>"A key", "attr_key"=>"a_key"}, {"name"=>"B key", "attr_key"=>"b_key"}])
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
              # HashWithIndifferentAccess is something Rails seems to use for the params hash
         
     | 
| 
      
 28 
     | 
    
         
            +
              it "should work with HashWithIndifferentAccess" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                hash = ActiveSupport::HashWithIndifferentAccess.new("name"=>"A key", "attr_key"=>"a_key")
         
     | 
| 
      
 30 
     | 
    
         
            +
                c = Category.create
         
     | 
| 
      
 31 
     | 
    
         
            +
                lambda {c.add_definitions(hash)}.should_not raise_error(NoMethodError)
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       27 
34 
     | 
    
         
             
              it "should not explode if nil is passed" do
         
     | 
| 
       28 
35 
     | 
    
         
             
                lambda {Category.create.add_definitions(nil)}.should_not raise_error(NoMethodError)
         
     | 
| 
       29 
36 
     | 
    
         
             
              end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: datts_right
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              hash:  
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 43
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              segments: 
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
8 
     | 
    
         
             
              - 0
         
     | 
| 
       9 
     | 
    
         
            -
              -  
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 9 
     | 
    
         
            +
              - 26
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.0.26
         
     | 
| 
       11 
11 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
12 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
13 
     | 
    
         
             
            - Ramon Tayag
         
     | 
| 
         @@ -15,7 +15,7 @@ autorequire: 
     | 
|
| 
       15 
15 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
16 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2011-04- 
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2011-04-27 00:00:00 +08:00
         
     | 
| 
       19 
19 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
20 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       21 
21 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |