chrono_model 0.12.2 → 0.12.3
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 -1
- data/lib/chrono_model/adapter.rb +10 -8
- data/lib/chrono_model/version.rb +1 -1
- data/spec/adapter_spec.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/matchers/function.rb +79 -0
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 867208c8ba66191c8cf3bdebbc9eb4d811d59625
         | 
| 4 | 
            +
              data.tar.gz: 4651e58743b71d6cb54bba59929fec7c10ae80ac
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5dd88e44a1fedb1bb33199f2483c7d008fda05c753510d74b0fdb1fd9a2966138a0838b68d08d8e088d8e6bd36c50588f76357d327a966f6af68abc520ccbc6e
         | 
| 7 | 
            +
              data.tar.gz: 297be09d1673a4235bc3168fdfdf087612740790d33ca99b0eff033f24738536854ff7044f024a1b86df9da84c5fdb1e43cd9e90da2e212c2e02c5ce39bc475d
         | 
    
        data/README.md
    CHANGED
    
    | @@ -66,7 +66,7 @@ All timestamps are _forcibly_ stored in as UTC, bypassing the | |
| 66 66 | 
             
            ## Requirements
         | 
| 67 67 |  | 
| 68 68 | 
             
            * Ruby >= 2.2 (1.9 to 2.1 could still work, but aren't supported).
         | 
| 69 | 
            -
            * Active Record 4.2 or 5. | 
| 69 | 
            +
            * Active Record 4.2, 5.0 or 5.1. NOTE: AR 4.2 is not compatible with Ruby 2.4. [Detailed matrix](https://travis-ci.org/ifad/chronomodel)
         | 
| 70 70 | 
             
            * PostgreSQL >= 9.3
         | 
| 71 71 | 
             
            * The `btree_gist` PostgreSQL extension
         | 
| 72 72 | 
             
            * The `plpython` PostgreSQL extension if you have *JSON* (*not* JSONB) columns
         | 
    
        data/lib/chrono_model/adapter.rb
    CHANGED
    
    | @@ -106,9 +106,7 @@ module ChronoModel | |
| 106 106 |  | 
| 107 107 | 
             
                    # Drop functions
         | 
| 108 108 | 
             
                    #
         | 
| 109 | 
            -
                     | 
| 110 | 
            -
                      execute "DROP FUNCTION chronomodel_#{name}_#{func}()"
         | 
| 111 | 
            -
                    end
         | 
| 109 | 
            +
                    chrono_drop_trigger_functions_for(name)
         | 
| 112 110 |  | 
| 113 111 | 
             
                    # Create view and functions
         | 
| 114 112 | 
             
                    #
         | 
| @@ -168,11 +166,7 @@ module ChronoModel | |
| 168 166 | 
             
                        #
         | 
| 169 167 | 
             
                        execute "DROP VIEW #{table_name}"
         | 
| 170 168 |  | 
| 171 | 
            -
                         | 
| 172 | 
            -
                          %w( insert update delete ).each do |func|
         | 
| 173 | 
            -
                            execute "DROP FUNCTION IF EXISTS #{table_name}_#{func}() CASCADE"
         | 
| 174 | 
            -
                          end
         | 
| 175 | 
            -
                        end
         | 
| 169 | 
            +
                        chrono_drop_trigger_functions_for(table_name)
         | 
| 176 170 |  | 
| 177 171 | 
             
                        _on_history_schema { execute "DROP TABLE #{table_name}" }
         | 
| 178 172 |  | 
| @@ -198,6 +192,8 @@ module ChronoModel | |
| 198 192 | 
             
                  return super unless is_chrono?(table_name)
         | 
| 199 193 |  | 
| 200 194 | 
             
                  _on_temporal_schema { execute "DROP TABLE #{table_name} CASCADE" }
         | 
| 195 | 
            +
             | 
| 196 | 
            +
                  chrono_drop_trigger_functions_for(table_name)
         | 
| 201 197 | 
             
                end
         | 
| 202 198 |  | 
| 203 199 | 
             
                # If adding an index to a temporal table, add it to the one in the
         | 
| @@ -852,6 +848,12 @@ module ChronoModel | |
| 852 848 | 
             
                    SQL
         | 
| 853 849 | 
             
                  end
         | 
| 854 850 |  | 
| 851 | 
            +
                  def chrono_drop_trigger_functions_for(table_name)
         | 
| 852 | 
            +
                    %w( insert update delete ).each do |func|
         | 
| 853 | 
            +
                      execute "DROP FUNCTION IF EXISTS chronomodel_#{table_name}_#{func}()"
         | 
| 854 | 
            +
                    end
         | 
| 855 | 
            +
                  end
         | 
| 856 | 
            +
             | 
| 855 857 | 
             
                  # In destructive changes, such as removing columns or changing column
         | 
| 856 858 | 
             
                  # types, the view must be dropped and recreated, while the change has
         | 
| 857 859 | 
             
                  # to be applied to the table in the temporal schema.
         | 
    
        data/lib/chrono_model/version.rb
    CHANGED
    
    
    
        data/spec/adapter_spec.rb
    CHANGED
    
    | @@ -9,6 +9,7 @@ shared_examples_for 'temporal table' do | |
| 9 9 | 
             
              it { is_expected.to have_temporal_backing }
         | 
| 10 10 | 
             
              it { is_expected.to have_history_backing }
         | 
| 11 11 | 
             
              it { is_expected.to have_history_extra_columns }
         | 
| 12 | 
            +
              it { is_expected.to have_history_functions }
         | 
| 12 13 | 
             
              it { is_expected.to have_public_interface }
         | 
| 13 14 |  | 
| 14 15 | 
             
              it { is_expected.to have_columns(columns) }
         | 
| @@ -23,6 +24,7 @@ shared_examples_for 'plain table' do | |
| 23 24 |  | 
| 24 25 | 
             
              it { is_expected.to_not have_temporal_backing }
         | 
| 25 26 | 
             
              it { is_expected.to_not have_history_backing }
         | 
| 27 | 
            +
              it { is_expected.to_not have_history_functions }
         | 
| 26 28 | 
             
              it { is_expected.to_not have_public_interface }
         | 
| 27 29 |  | 
| 28 30 | 
             
              it { is_expected.to have_columns(columns) }
         | 
| @@ -168,6 +170,7 @@ describe ChronoModel::Adapter do | |
| 168 170 | 
             
                it { is_expected.to_not have_public_backing }
         | 
| 169 171 | 
             
                it { is_expected.to_not have_temporal_backing }
         | 
| 170 172 | 
             
                it { is_expected.to_not have_history_backing }
         | 
| 173 | 
            +
                it { is_expected.to_not have_history_functions }
         | 
| 171 174 | 
             
                it { is_expected.to_not have_public_interface }
         | 
| 172 175 | 
             
              end
         | 
| 173 176 |  | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
| @@ -0,0 +1,79 @@ | |
| 1 | 
            +
            module ChronoTest::Matchers
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              module Column
         | 
| 4 | 
            +
                class HaveFunctions < ChronoTest::Matchers::Base
         | 
| 5 | 
            +
                  def initialize(functions, schema = 'public')
         | 
| 6 | 
            +
                    @functions = functions
         | 
| 7 | 
            +
                    @schema    = schema
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def description
         | 
| 11 | 
            +
                    'have functions'
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def matches?(table)
         | 
| 15 | 
            +
                    super(table)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    @matches = @functions.inject({}) do |h, name|
         | 
| 18 | 
            +
                      h.update(name => has_function?(name))
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    @matches.values.all?
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def failure_message
         | 
| 25 | 
            +
                    message_matches("expected #{@schema}.#{table} to have")
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def failure_message_when_negated
         | 
| 29 | 
            +
                    message_matches("expected #{@schema}.#{table} to not have")
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  protected
         | 
| 33 | 
            +
                    def has_function?(name)
         | 
| 34 | 
            +
                      select_value(<<-SQL, [name], 'Check function') == AR_TRUE
         | 
| 35 | 
            +
                        SELECT EXISTS(
         | 
| 36 | 
            +
                          SELECT 1
         | 
| 37 | 
            +
                          FROM pg_catalog.pg_proc p, pg_catalog.pg_namespace n
         | 
| 38 | 
            +
                          WHERE p.pronamespace = n.oid
         | 
| 39 | 
            +
                            AND n.nspname = 'public'
         | 
| 40 | 
            +
                            AND p.proname = ?
         | 
| 41 | 
            +
                        )
         | 
| 42 | 
            +
                      SQL
         | 
| 43 | 
            +
                    end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  private
         | 
| 46 | 
            +
                    def message_matches(message)
         | 
| 47 | 
            +
                      (message << ' ').tap do |message|
         | 
| 48 | 
            +
                        message << @matches.map do |name, match|
         | 
| 49 | 
            +
                          "a #{name} function"
         | 
| 50 | 
            +
                        end.compact.to_sentence
         | 
| 51 | 
            +
                      end
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def have_functions(*args)
         | 
| 56 | 
            +
                  HaveFunctions.new(*args)
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                class HaveHistoryFunctions < HaveFunctions
         | 
| 60 | 
            +
                  def initialize
         | 
| 61 | 
            +
                    @function_templates = [
         | 
| 62 | 
            +
                      'chronomodel_%s_insert',
         | 
| 63 | 
            +
                      'chronomodel_%s_update',
         | 
| 64 | 
            +
                      'chronomodel_%s_delete',
         | 
| 65 | 
            +
                    ]
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                  def matches?(table)
         | 
| 69 | 
            +
                    @functions = @function_templates.map {|t| t % [table] }
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    super(table)
         | 
| 72 | 
            +
                  end
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                def have_history_functions
         | 
| 76 | 
            +
                  HaveHistoryFunctions.new
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
              end
         | 
| 79 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: chrono_model
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.12. | 
| 4 | 
            +
              version: 0.12.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marcello Barnaba
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2018- | 
| 12 | 
            +
            date: 2018-07-11 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activerecord
         | 
| @@ -250,6 +250,7 @@ files: | |
| 250 250 | 
             
            - spec/support/helpers.rb
         | 
| 251 251 | 
             
            - spec/support/matchers/base.rb
         | 
| 252 252 | 
             
            - spec/support/matchers/column.rb
         | 
| 253 | 
            +
            - spec/support/matchers/function.rb
         | 
| 253 254 | 
             
            - spec/support/matchers/index.rb
         | 
| 254 255 | 
             
            - spec/support/matchers/schema.rb
         | 
| 255 256 | 
             
            - spec/support/matchers/table.rb
         | 
| @@ -302,6 +303,7 @@ test_files: | |
| 302 303 | 
             
            - spec/support/helpers.rb
         | 
| 303 304 | 
             
            - spec/support/matchers/base.rb
         | 
| 304 305 | 
             
            - spec/support/matchers/column.rb
         | 
| 306 | 
            +
            - spec/support/matchers/function.rb
         | 
| 305 307 | 
             
            - spec/support/matchers/index.rb
         | 
| 306 308 | 
             
            - spec/support/matchers/schema.rb
         | 
| 307 309 | 
             
            - spec/support/matchers/table.rb
         |