declare_schema 1.2.3.pre.ga.7 → 1.2.3.pre.ga.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.
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e09beef167920318bac9b447f693d1301cd3d50bc9299dc8fd815de987e08977
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: de03405c8b47000f1946dba49376753ecea9fb1a90dac78c2bf816b8eb2818b4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0d77e6527a3583e1c7a7fddb446f88a226218f74ff0f596f278f6f496570a3dc139cae28a3ce207cda37e365c83107e4c4c0832de868c357d0b21f752f7fb09f
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4f4fdff9bf470cf623de038e596462073078838a18d4a7ad1d8def80ee4178aba99a332e36c6b56d6caedb7094c4ec54e084bcaa39dce1a3393fde0a82d43fc9
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
| 
         @@ -37,10 +37,6 @@ module DeclareSchema 
     | 
|
| 
       37 
37 
     | 
    
         
             
                    join_table
         
     | 
| 
       38 
38 
     | 
    
         
             
                  end
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
                  def index_name
         
     | 
| 
       41 
     | 
    
         
            -
                    "index_#{table_name}_on_#{foreign_keys.first}_#{foreign_keys.last}"
         
     | 
| 
       42 
     | 
    
         
            -
                  end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
40 
     | 
    
         
             
                  def field_specs
         
     | 
| 
       45 
41 
     | 
    
         
             
                    foreign_keys.each_with_index.each_with_object({}) do |(v, position), result|
         
     | 
| 
       46 
42 
     | 
    
         
             
                      result[v] = ::DeclareSchema::Model::FieldSpec.new(self, v, :bigint, position: position, null: false)
         
     | 
| 
         @@ -57,7 +53,7 @@ module DeclareSchema 
     | 
|
| 
       57 
53 
     | 
    
         | 
| 
       58 
54 
     | 
    
         
             
                  def index_definitions_with_primary_key
         
     | 
| 
       59 
55 
     | 
    
         
             
                    [
         
     | 
| 
       60 
     | 
    
         
            -
                      IndexDefinition.new(self, foreign_keys, unique: true, name:  
     | 
| 
      
 56 
     | 
    
         
            +
                      IndexDefinition.new(self, foreign_keys, unique: true, name: Model::IndexDefinition::PRIMARY_KEY_NAME), # creates a primary composite key on both foreign keys
         
     | 
| 
       61 
57 
     | 
    
         
             
                      IndexDefinition.new(self, foreign_keys.last) # not unique by itself; combines with primary key to be unique
         
     | 
| 
       62 
58 
     | 
    
         
             
                    ]
         
     | 
| 
       63 
59 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -102,12 +102,37 @@ RSpec.describe DeclareSchema::Model::HabtmModelShim do 
     | 
|
| 
       102 
102 
     | 
    
         
             
                    expect(result.size).to eq(2), result.inspect
         
     | 
| 
       103 
103 
     | 
    
         | 
| 
       104 
104 
     | 
    
         
             
                    expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
         
     | 
| 
       105 
     | 
    
         
            -
                    expect(result.first.name).to eq(' 
     | 
| 
      
 105 
     | 
    
         
            +
                    expect(result.first.name).to eq('PRIMARY')
         
     | 
| 
       106 
106 
     | 
    
         
             
                    expect(result.first.fields).to eq(['parent_1_id', 'parent_2_id'])
         
     | 
| 
       107 
107 
     | 
    
         
             
                    expect(result.first.unique).to be_truthy
         
     | 
| 
       108 
108 
     | 
    
         
             
                  end
         
     | 
| 
       109 
109 
     | 
    
         
             
                end
         
     | 
| 
       110 
110 
     | 
    
         | 
| 
      
 111 
     | 
    
         
            +
                context 'when table and foreign key names are long' do
         
     | 
| 
      
 112 
     | 
    
         
            +
                  let(:join_table) { "advertiser_campaigns_tracking_pixels" }
         
     | 
| 
      
 113 
     | 
    
         
            +
                  let(:foreign_keys) { ['advertiser_campaign', 'tracking_pixel'] }
         
     | 
| 
      
 114 
     | 
    
         
            +
                  let(:foreign_key_classes) { [Table1, Table2] }
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 117 
     | 
    
         
            +
                    class Table1 < ActiveRecord::Base
         
     | 
| 
      
 118 
     | 
    
         
            +
                      self.table_name = 'advertiser_campaign'
         
     | 
| 
      
 119 
     | 
    
         
            +
                    end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                    class Table2 < ActiveRecord::Base
         
     | 
| 
      
 122 
     | 
    
         
            +
                      self.table_name = 'tracking_pixel'
         
     | 
| 
      
 123 
     | 
    
         
            +
                    end
         
     | 
| 
      
 124 
     | 
    
         
            +
                  end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                  it 'returns two index definitions and does not raise a IndexNameTooLongError' do
         
     | 
| 
      
 127 
     | 
    
         
            +
                    result = subject.index_definitions_with_primary_key
         
     | 
| 
      
 128 
     | 
    
         
            +
                    expect(result.size).to eq(2), result.inspect
         
     | 
| 
      
 129 
     | 
    
         
            +
                    expect(result.first).to be_a(::DeclareSchema::Model::IndexDefinition)
         
     | 
| 
      
 130 
     | 
    
         
            +
                    expect(result.first.name).to eq('PRIMARY')
         
     | 
| 
      
 131 
     | 
    
         
            +
                    expect(result.first.fields).to eq(['advertiser_campaign', 'tracking_pixel'])
         
     | 
| 
      
 132 
     | 
    
         
            +
                    expect(result.first.unique).to be_truthy
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
       111 
136 
     | 
    
         
             
                describe '#index_definitions' do
         
     | 
| 
       112 
137 
     | 
    
         
             
                  it 'returns index_definitions_with_primary_key' do
         
     | 
| 
       113 
138 
     | 
    
         
             
                    result = subject.index_definitions
         
     |