From a3254e020ca7434ce711cf144990b2a7dfc0c0e0 Mon Sep 17 00:00:00 2001 From: Andrius Chamentauskas Date: Thu, 22 Dec 2022 14:50:52 +0200 Subject: [PATCH] Migrate to PostgreSQL (#13) --- .github/workflows/ruby.yml | 1 - .rubocop.yml | 2 +- Appraisals | 3 +-- CHANGELOG.md | 3 +++ docker-compose.yml | 14 +++++++++++++ gemfiles/rails.4.2.gemfile | 15 -------------- gemfiles/rails.5.0.gemfile | 1 - gemfiles/rails.5.1.gemfile | 1 - gemfiles/rails.5.2.gemfile | 1 - granite-form.gemspec | 12 +++++------ .../associations/references_many_spec.rb | 8 +++++--- .../model/associations/references_one_spec.rb | 10 ++++++---- .../reflections/references_many_spec.rb | 2 +- .../reflections/references_one_spec.rb | 2 +- spec/spec_helper.rb | 15 -------------- spec/support/active_record.rb | 20 +++++++++++++++++++ 16 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 gemfiles/rails.4.2.gemfile create mode 100644 spec/support/active_record.rb diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 5509661..e36e3aa 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -10,7 +10,6 @@ jobs: fail-fast: false matrix: include: - - { ruby: '2.3', rails: '4.2' } - { ruby: '2.4', rails: '5.0' } - { ruby: '2.5', rails: '5.1' } - { ruby: '2.6', rails: '5.2' } diff --git a/.rubocop.yml b/.rubocop.yml index 75053dd..0ab4ce1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml AllCops: DisplayCopNames: true - TargetRubyVersion: 2.3.0 + TargetRubyVersion: 2.4.0 Lint/AmbiguousBlockAssociation: Enabled: false diff --git a/Appraisals b/Appraisals index d115aa7..f88a45a 100644 --- a/Appraisals +++ b/Appraisals @@ -1,8 +1,7 @@ -%w[4.2 5.0 5.1 5.2 6.0 6.1 7.0].each do |version| +%w[5.0 5.1 5.2 6.0 6.1 7.0].each do |version| appraise "rails.#{version}" do gem 'activesupport', "~> #{version}.0" gem 'activemodel', "~> #{version}.0" gem 'activerecord', "~> #{version}.0" - gem 'sqlite3', '~> 1.3.6' if version < '6.0' end end diff --git a/CHANGELOG.md b/CHANGELOG.md index 18b61f9..63c2f6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## Next - [BREAKING] Stop automatically saving `references_one`/`references_many` when applying changes. +- [BREAKING] Removed Lifecycle module. `embeds_many`/`embeds_one` objects can no longer be created/saved/updated/destroyed. +- [BREAKING] Due to changes above `accepts_nested_attributes_for` for `embeds_many`/`embeds_one` associations no longer marks objects for destruction but simply removes them, making changes instantly. +- Drop support for ruby 2.3 and rails 4.2 ## v0.2.0 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b5dd72b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.7' +services: + postgresql: + image: 'postgres:12.4' + environment: + POSTGRES_USER: granite + POSTGRES_PASSWORD: granite + volumes: + - granite_dbdata:/var/lib/postgresql/data + ports: + - '5432:5432' + +volumes: + granite_dbdata: diff --git a/gemfiles/rails.4.2.gemfile b/gemfiles/rails.4.2.gemfile deleted file mode 100644 index 69eea35..0000000 --- a/gemfiles/rails.4.2.gemfile +++ /dev/null @@ -1,15 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "activesupport", "~> 4.2.0" -gem "activemodel", "~> 4.2.0" -gem "activerecord", "~> 4.2.0" -gem "sqlite3", "~> 1.3.6" - -group :test do - gem "guard" - gem "guard-rspec" -end - -gemspec path: "../" diff --git a/gemfiles/rails.5.0.gemfile b/gemfiles/rails.5.0.gemfile index d4ee631..3494b66 100644 --- a/gemfiles/rails.5.0.gemfile +++ b/gemfiles/rails.5.0.gemfile @@ -5,7 +5,6 @@ source "https://rubygems.org" gem "activesupport", "~> 5.0.0" gem "activemodel", "~> 5.0.0" gem "activerecord", "~> 5.0.0" -gem "sqlite3", "~> 1.3.6" group :test do gem "guard" diff --git a/gemfiles/rails.5.1.gemfile b/gemfiles/rails.5.1.gemfile index a73db75..552d36e 100644 --- a/gemfiles/rails.5.1.gemfile +++ b/gemfiles/rails.5.1.gemfile @@ -5,7 +5,6 @@ source "https://rubygems.org" gem "activesupport", "~> 5.1.0" gem "activemodel", "~> 5.1.0" gem "activerecord", "~> 5.1.0" -gem "sqlite3", "~> 1.3.6" group :test do gem "guard" diff --git a/gemfiles/rails.5.2.gemfile b/gemfiles/rails.5.2.gemfile index 8eea118..32b69b8 100644 --- a/gemfiles/rails.5.2.gemfile +++ b/gemfiles/rails.5.2.gemfile @@ -5,7 +5,6 @@ source "https://rubygems.org" gem "activesupport", "~> 5.2.0" gem "activemodel", "~> 5.2.0" gem "activerecord", "~> 5.2.0" -gem "sqlite3", "~> 1.3.6" group :test do gem "guard" diff --git a/granite-form.gemspec b/granite-form.gemspec index 2b2efe3..fe6919a 100644 --- a/granite-form.gemspec +++ b/granite-form.gemspec @@ -11,22 +11,22 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.name = 'granite-form' gem.require_paths = ['lib'] - gem.required_ruby_version = '>= 2.3.0' + gem.required_ruby_version = '>= 2.4.0' gem.version = Granite::Form::VERSION - gem.add_development_dependency 'actionpack', '>= 4.2' - gem.add_development_dependency 'activerecord', '>= 4.2' + gem.add_development_dependency 'actionpack', '>= 5.0' + gem.add_development_dependency 'activerecord', '>= 5.0' gem.add_development_dependency 'appraisal' gem.add_development_dependency 'bump' gem.add_development_dependency 'database_cleaner' + gem.add_development_dependency 'pg' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec', '~> 3.7.0' gem.add_development_dependency 'rspec-its' gem.add_development_dependency 'rubocop', '0.52.1' - gem.add_development_dependency 'sqlite3' gem.add_development_dependency 'uuidtools' - gem.add_runtime_dependency 'activemodel', '>= 4.2' - gem.add_runtime_dependency 'activesupport', '>= 4.2' + gem.add_runtime_dependency 'activemodel', '>= 5.0' + gem.add_runtime_dependency 'activesupport', '>= 5.0' gem.add_runtime_dependency 'tzinfo' end diff --git a/spec/granite/form/model/associations/references_many_spec.rb b/spec/granite/form/model/associations/references_many_spec.rb index 52f6451..3eedc79 100644 --- a/spec/granite/form/model/associations/references_many_spec.rb +++ b/spec/granite/form/model/associations/references_many_spec.rb @@ -4,7 +4,7 @@ before do stub_model(:dummy) stub_class(:author, ActiveRecord::Base) do - scope :name_starts_with_a, -> { where('name LIKE "a%"') } + scope :name_starts_with_a, -> { where('name ILIKE "a%"') } validates :name, presence: true end @@ -33,7 +33,9 @@ end describe 'book#inspect' do - specify { expect(existing_book.inspect).to eq('#]>, title: "Genesis", author_ids: [1]>') } + specify { expect(existing_book.inspect).to eq(<<~STR.chomp) } + #, title: "Genesis", author_ids: [#{author.id}]> + STR end describe '#scope' do @@ -213,7 +215,7 @@ end specify do expect { association.concat(new_author1) } - .to change { book.read_attribute(:author_ids) }.from([]).to([1]) + .to change { book.read_attribute(:author_ids) }.from([]).to([new_author1.id]) end specify do diff --git a/spec/granite/form/model/associations/references_one_spec.rb b/spec/granite/form/model/associations/references_one_spec.rb index 85771b7..4369aa5 100644 --- a/spec/granite/form/model/associations/references_one_spec.rb +++ b/spec/granite/form/model/associations/references_one_spec.rb @@ -29,7 +29,9 @@ end describe 'book#inspect' do - specify { expect(existing_book.inspect).to eq('#>, title: "My Life", author_id: 1>') } + specify { expect(existing_book.inspect).to eq(<<~STR.chomp) } + #, title: "My Life", author_id: #{author.id}> + STR end describe '#target' do @@ -110,7 +112,7 @@ end context 'persisted owner' do - let(:new_author) { Author.create(name: 'Morty') } + let(:new_author) { Author.create!(name: 'Morty') } specify do expect { association.writer(stub_model(:dummy).new) } @@ -125,7 +127,7 @@ end specify do expect { association.writer(new_author) } - .to change { association.reader.try(:attributes) }.from(nil).to('id' => 1, 'name' => 'Morty') + .to change { association.reader.try(:attributes) }.from(nil).to('id' => new_author.id, 'name' => 'Morty') end specify do expect { association.writer(new_author) } @@ -159,7 +161,7 @@ specify do expect { existing_association.writer(new_author) } .to change { existing_association.reader.try(:attributes) } - .from('id' => 1, 'name' => 'Johny').to('id' => 2, 'name' => 'Morty') + .from('id' => author.id, 'name' => 'Johny').to('id' => new_author.id, 'name' => 'Morty') end specify do expect { existing_association.writer(new_author) } diff --git a/spec/granite/form/model/associations/reflections/references_many_spec.rb b/spec/granite/form/model/associations/reflections/references_many_spec.rb index 3b8c190..47ae80b 100644 --- a/spec/granite/form/model/associations/reflections/references_many_spec.rb +++ b/spec/granite/form/model/associations/reflections/references_many_spec.rb @@ -4,7 +4,7 @@ before do stub_class(:author, ActiveRecord::Base) do scope :name_starts_with_a, -> { name_starts_with('a') } - scope :name_starts_with, ->(letter) { where("name LIKE '#{letter}%'") } + scope :name_starts_with, ->(letter) { where("name ILIKE '#{letter}%'") } end stub_model(:book) do diff --git a/spec/granite/form/model/associations/reflections/references_one_spec.rb b/spec/granite/form/model/associations/reflections/references_one_spec.rb index 88dbc73..04aa383 100644 --- a/spec/granite/form/model/associations/reflections/references_one_spec.rb +++ b/spec/granite/form/model/associations/reflections/references_one_spec.rb @@ -4,7 +4,7 @@ before do stub_class(:author, ActiveRecord::Base) do scope :name_starts_with_a, -> { name_starts_with('a') } - scope :name_starts_with, ->(letter) { where("name LIKE '#{letter}%'") } + scope :name_starts_with, ->(letter) { where("name ILIKE '#{letter}%'") } end stub_model(:book) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3876893..a8ec74f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,21 +10,6 @@ Dir[File.join(__dir__, 'support', '**', '*.rb')].sort.each { |f| require f } -ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') -ActiveRecord::Base.logger = Logger.new('/dev/null') - -ActiveRecord::Schema.define do - create_table :users do |t| - t.column :email, :string - t.column :projects, :text - t.column :profile, :text - end - - create_table :authors do |t| - t.column :name, :string - end -end - RSpec.configure do |config| config.mock_with :rspec config.order = :random diff --git a/spec/support/active_record.rb b/spec/support/active_record.rb new file mode 100644 index 0000000..8fc0079 --- /dev/null +++ b/spec/support/active_record.rb @@ -0,0 +1,20 @@ +ActiveRecord::Base.establish_connection( + adapter: 'postgresql', + database: 'granite', + username: 'granite', + password: 'granite', + host: 'localhost' +) +ActiveRecord::Base.logger = Logger.new('/dev/null') + +ActiveRecord::Schema.define do + create_table :users, force: :cascade do |t| + t.column :email, :string + t.column :projects, :text + t.column :profile, :text + end + + create_table :authors, force: :cascade do |t| + t.column :name, :string + end +end