|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe 'DeclareSchema Model FieldSpec' do |
| 4 | + before do |
| 5 | + load File.expand_path('prepare_testapp.rb', __dir__) |
| 6 | + end |
| 7 | + |
| 8 | + context 'There are no model columns to change' do |
| 9 | + it '#different_to should return false for int8 == int8' do |
| 10 | + subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :integer, limit: 8, null: false, position: 0) |
| 11 | + |
| 12 | + case Rails::VERSION::MAJOR |
| 13 | + when 4 |
| 14 | + cast_type = ActiveRecord::Type::Integer.new(limit: 8) |
| 15 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "integer(8)", false) |
| 16 | + else |
| 17 | + sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "integer(8)", type: :integer, limit: 8) |
| 18 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts") |
| 19 | + end |
| 20 | + |
| 21 | + expect(subject.different_to?(subject.name, col)).to eq(false) |
| 22 | + end |
| 23 | + |
| 24 | + it '#different_to should return false for bigint == bigint' do |
| 25 | + subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :bigint, null: false, position: 0) |
| 26 | + |
| 27 | + case Rails::VERSION::MAJOR |
| 28 | + when 4 |
| 29 | + cast_type = ActiveRecord::Type::BigInteger.new(limit: 8) |
| 30 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "bigint(20)", false) |
| 31 | + else |
| 32 | + sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "bigint(20)", type: :integer, limit: 8) |
| 33 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts") |
| 34 | + end |
| 35 | + |
| 36 | + expect(subject.different_to?(subject.name, col)).to eq(false) |
| 37 | + end |
| 38 | + |
| 39 | + it '#different_to should return false for int8 == bigint' do |
| 40 | + subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :integer, limit: 8, null: false, position: 0) |
| 41 | + |
| 42 | + case Rails::VERSION::MAJOR |
| 43 | + when 4 |
| 44 | + cast_type = ActiveRecord::Type::BigInteger.new(limit: 8) |
| 45 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "bigint(20)", false) |
| 46 | + else |
| 47 | + sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "bigint(20)", type: :integer, limit: 8) |
| 48 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts") |
| 49 | + end |
| 50 | + |
| 51 | + expect(subject.different_to?(subject.name, col)).to eq(false) |
| 52 | + end |
| 53 | + |
| 54 | + it '#different_to should return false for bigint == int8' do |
| 55 | + subject = DeclareSchema::Model::FieldSpec.new(Object, :price, :bigint, null: false, position: 0) |
| 56 | + |
| 57 | + case Rails::VERSION::MAJOR |
| 58 | + when 4 |
| 59 | + cast_type = ActiveRecord::Type::Integer.new(limit: 8) |
| 60 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, cast_type, "integer(8)", false) |
| 61 | + else |
| 62 | + sql_type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "integer(8)", type: :integer, limit: 8) |
| 63 | + col = ActiveRecord::ConnectionAdapters::Column.new("price", nil, sql_type_metadata, false, "adverts") |
| 64 | + end |
| 65 | + |
| 66 | + expect(subject.different_to?(subject.name, col)).to eq(false) |
| 67 | + end |
| 68 | + end |
| 69 | +end |
0 commit comments