Skip to content

Commit

Permalink
Migrate to PostgreSQL (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
andriusch authored Dec 22, 2022
1 parent bdf1abc commit a3254e0
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 52 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.3.0
TargetRubyVersion: 2.4.0

Lint/AmbiguousBlockAssociation:
Enabled: false
Expand Down
3 changes: 1 addition & 2 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
15 changes: 0 additions & 15 deletions gemfiles/rails.4.2.gemfile

This file was deleted.

1 change: 0 additions & 1 deletion gemfiles/rails.5.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails.5.1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion gemfiles/rails.5.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions granite-form.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions spec/granite/form/model/associations/references_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -33,7 +33,9 @@
end

describe 'book#inspect' do
specify { expect(existing_book.inspect).to eq('#<Book authors: #<ReferencesMany [#<Author id: 1, name: "Rick">]>, title: "Genesis", author_ids: [1]>') }
specify { expect(existing_book.inspect).to eq(<<~STR.chomp) }
#<Book authors: #<ReferencesMany [#{author.inspect}]>, title: "Genesis", author_ids: [#{author.id}]>
STR
end

describe '#scope' do
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions spec/granite/form/model/associations/references_one_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
end

describe 'book#inspect' do
specify { expect(existing_book.inspect).to eq('#<Book author: #<ReferencesOne #<Author id: 1, name: "Johny">>, title: "My Life", author_id: 1>') }
specify { expect(existing_book.inspect).to eq(<<~STR.chomp) }
#<Book author: #<ReferencesOne #{author.inspect}>, title: "My Life", author_id: #{author.id}>
STR
end

describe '#target' do
Expand Down Expand Up @@ -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) }
Expand All @@ -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) }
Expand Down Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions spec/support/active_record.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a3254e0

Please sign in to comment.