active_record-acts_as 1.0.6 → 1.0.7
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/active_record/acts_as.rb +1 -0
- data/lib/active_record/acts_as/class_methods.rb +14 -0
- data/lib/active_record/acts_as/instance_methods.rb +16 -0
- data/lib/active_record/acts_as/relation.rb +3 -0
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +34 -0
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 7387f8a9b958e1010c9c86367631e5be078d6329
         | 
| 4 | 
            +
              data.tar.gz: 31705e7f709ae00673bc2cf9bddcf72cc7a2eda9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 507a0fd8e3609ceb749a1f8a3ee9ae051de0094fb769778a661ff91f0ed9bf0bb4f8001267c68db76f70f02f64f0c088d48533c599f40d76b12eacf1e8932b04
         | 
| 7 | 
            +
              data.tar.gz: aebd0d7c848b0f53639491582c3d29187ed0d152324d861ebfbbb0441f792c83a61f95bb8d0d8ccce6993be6f899203dc0d1c790ac523c09d16d3f55179a4e85
         | 
    
        data/README.md
    CHANGED
    
    
| @@ -3,6 +3,7 @@ require 'active_record' | |
| 3 3 | 
             
            require 'active_record/acts_as/version'
         | 
| 4 4 | 
             
            require 'active_record/acts_as/relation'
         | 
| 5 5 | 
             
            require 'active_record/acts_as/migration'
         | 
| 6 | 
            +
            require 'active_record/acts_as/class_methods'
         | 
| 6 7 | 
             
            require 'active_record/acts_as/instance_methods'
         | 
| 7 8 | 
             
            require 'active_record/acts_as/querying'
         | 
| 8 9 |  | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module ActiveRecord
         | 
| 2 | 
            +
              module ActsAs
         | 
| 3 | 
            +
                module ClassMethods
         | 
| 4 | 
            +
                  def self.included(module_)
         | 
| 5 | 
            +
                    module_.alias_method_chain :_reflections, :acts_as
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def _reflections_with_acts_as
         | 
| 9 | 
            +
                    @_reflections_acts_as_cache ||=
         | 
| 10 | 
            +
                      _reflections_without_acts_as.reverse_merge(acting_as_model._reflections)
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -72,6 +72,22 @@ module ActiveRecord | |
| 72 72 | 
             
                    acting_as_persisted? ? super | (acting_as.attribute_names - [acting_as_reflection.type, acting_as_reflection.foreign_key]) : super
         | 
| 73 73 | 
             
                  end
         | 
| 74 74 |  | 
| 75 | 
            +
                  def has_attribute?(attr_name, as_original_class = false)
         | 
| 76 | 
            +
                    if as_original_class
         | 
| 77 | 
            +
                      super(attr_name)
         | 
| 78 | 
            +
                    else
         | 
| 79 | 
            +
                      super(attr_name) || acting_as.has_attribute?(attr_name)
         | 
| 80 | 
            +
                    end
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  def column_for_attribute(name)
         | 
| 84 | 
            +
                    if has_attribute?(name, true)
         | 
| 85 | 
            +
                      super(name)
         | 
| 86 | 
            +
                    else
         | 
| 87 | 
            +
                      acting_as.column_for_attribute(name)
         | 
| 88 | 
            +
                    end
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 75 91 |  | 
| 76 92 | 
             
                  def respond_to?(name, include_private = false, as_original_class = false)
         | 
| 77 93 | 
             
                    as_original_class ? super(name, include_private) : super(name, include_private) || acting_as.respond_to?(name)
         | 
    
        data/spec/acts_as_spec.rb
    CHANGED
    
    | @@ -111,6 +111,40 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do | |
| 111 111 | 
             
                end
         | 
| 112 112 | 
             
              end
         | 
| 113 113 |  | 
| 114 | 
            +
              describe "#has_attribute?" do
         | 
| 115 | 
            +
                context "when the attribute is defined on the superclass" do
         | 
| 116 | 
            +
                  it "queries the superclass" do
         | 
| 117 | 
            +
                    expect(pen.has_attribute?(:name)).to be_truthy
         | 
| 118 | 
            +
                  end
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                context "when the attribute is defined on the subclass" do
         | 
| 122 | 
            +
                  it "queries the subclass" do
         | 
| 123 | 
            +
                    expect(pen.has_attribute?(:color)).to be_truthy
         | 
| 124 | 
            +
                  end
         | 
| 125 | 
            +
                end
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
              describe "#column_for_attribute" do
         | 
| 129 | 
            +
                context "when the attribute is defined on the superclass" do
         | 
| 130 | 
            +
                  it "queries the superclass" do
         | 
| 131 | 
            +
                    expect(pen.column_for_attribute(:name)).to eq(pen.product.column_for_attribute(:name))
         | 
| 132 | 
            +
                  end
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                context "when the attribute is defined on the subclass" do
         | 
| 136 | 
            +
                  it "queries the subclass" do
         | 
| 137 | 
            +
                    expect(pen.column_for_attribute(:color)).not_to be_nil
         | 
| 138 | 
            +
                  end
         | 
| 139 | 
            +
                end
         | 
| 140 | 
            +
              end
         | 
| 141 | 
            +
             | 
| 142 | 
            +
              describe "._reflections" do
         | 
| 143 | 
            +
                it "merges the reflections on both superclass and subclass" do
         | 
| 144 | 
            +
                  expect(Pen._reflections.length).to eq(Product._reflections.length + 1)
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
              end
         | 
| 147 | 
            +
             | 
| 114 148 | 
             
              it "have supermodel attributes accessible on creation" do
         | 
| 115 149 | 
             
                expect{Pen.create(pen_attributes)}.to_not raise_error
         | 
| 116 150 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: active_record-acts_as
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Hassan Zamani
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-07-21 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: sqlite3
         | 
| @@ -117,6 +117,7 @@ files: | |
| 117 117 | 
             
            - Rakefile
         | 
| 118 118 | 
             
            - active_record-acts_as.gemspec
         | 
| 119 119 | 
             
            - lib/active_record/acts_as.rb
         | 
| 120 | 
            +
            - lib/active_record/acts_as/class_methods.rb
         | 
| 120 121 | 
             
            - lib/active_record/acts_as/instance_methods.rb
         | 
| 121 122 | 
             
            - lib/active_record/acts_as/migration.rb
         | 
| 122 123 | 
             
            - lib/active_record/acts_as/querying.rb
         | 
| @@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 149 150 | 
             
                  version: '0'
         | 
| 150 151 | 
             
            requirements: []
         | 
| 151 152 | 
             
            rubyforge_project: 
         | 
| 152 | 
            -
            rubygems_version: 2.4. | 
| 153 | 
            +
            rubygems_version: 2.4.8
         | 
| 153 154 | 
             
            signing_key: 
         | 
| 154 155 | 
             
            specification_version: 4
         | 
| 155 156 | 
             
            summary: Simulate multi-table inheritance for activerecord models
         |