Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.5'
- '3.4'
- '3.3'
- '3.2'
Expand Down
8 changes: 8 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Lint/EmptyClass:
Exclude:
- "spec/**/*.rb"

Lint/NestedMethodDefinition:
Exclude:
- "spec/**/*.rb"

Lint/RaiseException:
Enabled: false

Expand All @@ -63,6 +67,8 @@ Lint/SuppressedException:

Metrics/AbcSize:
Max: 20
Exclude:
- "spec/**/*.rb"

Metrics/BlockLength:
Enabled: false
Expand All @@ -76,6 +82,8 @@ Metrics/CyclomaticComplexity:

Metrics/MethodLength:
Max: 22
Exclude:
- "spec/**/*.rb"

Naming/FileName:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/sql/plugin/associates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def associate(
def with_association(name, opts = EMPTY_HASH)
self.class.build(
relation,
**options, associations: associations.merge(name => opts)
**options, associations: { **associations, name => opts }
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rom/sql/schema/inferrer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def call(schema, gateway)
else
infer_from_attributes(gateway, schema, **super)
end
rescue Sequel::Error => e
rescue ::Sequel::Error => e
on_error(schema.name, e)
{ **FALLBACK_SCHEMA, indexes: schema.indexes }
end
Expand Down
6 changes: 3 additions & 3 deletions spec/extensions/postgres/attribute/array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

include_context 'database setup'

before do
setup_relations do
conf.relation(:pg_arrays) do
schema(infer: true)
end
Expand All @@ -16,7 +16,7 @@
end

context 'with a primitive type' do
before do
setup_tables do
conn.create_table :pg_arrays do
column :numbers, 'int[]'
end
Expand All @@ -34,7 +34,7 @@
end

context 'with a custom json type' do
before do
setup_tables do
conn.create_table :pg_arrays do
column :meta, 'json[]'
end
Expand Down
48 changes: 25 additions & 23 deletions spec/extensions/postgres/attribute/range_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,6 @@
RSpec.describe 'ROM::SQL::Attribute', :postgres do
include_context 'database setup'

def create_ranges_table(db_type, values)
conn.create_table :pg_ranges do
primary_key :id
text :name

send(db_type, :range)
end

conf.relation(:pg_ranges) do
schema(:pg_ranges, infer: true)
end

conf.commands(:pg_ranges) do
define(:create)
end

values.each do |key, value|
commands[:pg_ranges].create.(name: key.to_s, range: value)
end
end

shared_examples 'range type' do
let(:rel) { pg_ranges.select { [name] } }

Expand Down Expand Up @@ -106,10 +85,33 @@ def create_ranges_table(db_type, values)
let(:pg_ranges) { relations[:pg_ranges] }
let(:range_value) { ROM::SQL::Postgres::Values::Range }

before do
setup_tables do
conn.extension(:pg_range)
conn.drop_table?(:pg_ranges)
create_ranges_table(db_type, values)

ctx = self
conn.create_table :pg_ranges do
primary_key :id
text :name

send(ctx.db_type, :range)
end
end

setup_relations do
conf.relation(:pg_ranges) do
schema(:pg_ranges, infer: true)
end

conf.commands(:pg_ranges) do
define(:create)
end
end

seed do
values.each do |key, value|
commands[:pg_ranges].create.(name: key.to_s, range: value)
end
end

describe 'numrange' do
Expand Down
28 changes: 23 additions & 5 deletions spec/extensions/postgres/attribute_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
RSpec.describe 'ROM::SQL::Attribute', :postgres do
include_context 'database setup'

before do
setup_tables do
conn.drop_table?(:pg_people)
conn.drop_table?(:people)
end

setup_relations do
conf.relation(:people) do
schema(:pg_people, infer: true)
end
Expand All @@ -17,18 +19,22 @@

%i[json jsonb].each do |type|
describe "using arrays in #{type}" do
before do
setup_tables do
conn.create_table :pg_people do
primary_key :id
String :name
column :fields, type
end
end

setup_relations do
conf.commands(:people) do
define(:create)
define(:update)
end
end

seed do
create_person.(
name: 'John Doe',
fields: [
Expand Down Expand Up @@ -100,18 +106,22 @@
next unless type == :jsonb

describe "using maps in #{type}" do
before do
setup_tables do
conn.create_table :pg_people do
primary_key :id
String :name
column :data, type
end
end

setup_relations do
conf.commands(:people) do
define(:create)
define(:update)
end
end

seed do
create_person.(name: 'John Doe', data: { age: 30, height: 180 })
create_person.(name: 'Jade Doe', data: { age: 25 })
end
Expand Down Expand Up @@ -160,19 +170,23 @@
end

describe 'using array types' do
before do
setup_tables do
conn.create_table :pg_people do
primary_key :id
String :name
column :emails, 'text[]'
column :bigids, 'bigint[]'
end
end

setup_relations do
conf.commands(:people) do
define(:create)
define(:update)
end
end

seed do
create_person.(name: 'John Doe', emails: %w[john@doe.com john@example.com], bigids: [84])
create_person.(name: 'Jade Doe', emails: %w[jade@hotmail.com], bigids: [42])
end
Expand Down Expand Up @@ -253,7 +267,7 @@
end

describe 'using ltree types' do
before do
setup_tables do
conn.execute('create extension if not exists ltree')

conn.create_table :pg_people do
Expand All @@ -262,12 +276,16 @@
column :ltree_tags, :ltree
column :parents_tags, 'ltree[]', default: []
end
end

setup_relations do
conf.commands(:people) do
define(:create)
define(:update)
end
end

seed do
create_person.(name: 'John Wilkson', ltree_tags: ltree('Bottom'), parents_tags: [ltree('Top'), ltree('Top.Building')])
create_person.(name: 'John Wayne', ltree_tags: ltree('Bottom.Countries'), parents_tags: [ltree('Left'), ltree('Left.Parks')])
create_person.(name: 'John Fake', ltree_tags: ltree('Bottom.Cities'), parents_tags: [ltree('Top.Building.EmpireState'), ltree('Top.Building.EmpireState.381')])
Expand Down
10 changes: 7 additions & 3 deletions spec/extensions/postgres/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
RSpec.describe 'PostgreSQL extension', :postgres do
include_context 'database setup'

before do
setup_tables do
conn.drop_table?(:pg_people)
conn.drop_table?(:people)
end

context 'with arrays' do
before do
setup_tables do
conn.create_table :pg_people do
primary_key :id
String :name
column :tags, 'text[]'
column :allowed_subnets, 'cidr[]'
end
end

setup_relations do
conf.relation(:people) do
schema(:pg_people, infer: true)
end
Expand Down Expand Up @@ -85,13 +87,15 @@
end

context 'with jsonb' do
before do
setup_tables do
conn.create_table :pg_people do
primary_key :id
String :name
column :attributes, 'jsonb'
end
end

setup_relations do
conf.relation(:people) do
schema(:pg_people, infer: true)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:puzzle_solvers) { relations[:puzzle_solvers] }

with_adapters do
before do
setup_tables do
conn.create_table(:puzzles) do
primary_key :id
column :text, String, null: false
Expand All @@ -26,7 +26,9 @@
foreign_key :puzzle_id, :puzzles, null: false
primary_key [:solver_id, :puzzle_id]
end
end

setup_relations do
conf.relation(:puzzles) { schema(infer: true) }

conf.relation(:puzzle_solvers) do
Expand All @@ -46,7 +48,9 @@
end
end
end
end

seed do
p1_id = relations[:puzzles].insert(text: 'P1')
p2_id = relations[:puzzles].insert(text: 'P2')
p3_id = relations[:puzzles].insert(text: 'P3')
Expand Down
6 changes: 5 additions & 1 deletion spec/integration/associations/many_to_many/from_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let(:puzzle_solvers) { relations[:puzzle_solvers] }

with_adapters do
before do
setup_tables do
conn.create_table(:puzzles) do
primary_key :id
column :text, String, null: false
Expand All @@ -27,7 +27,9 @@
foreign_key :puzzle_id, :puzzles, null: false
primary_key [:user_id, :puzzle_id]
end
end

setup_relations do
conf.relation(:puzzles) do
schema(infer: true)

Expand All @@ -54,7 +56,9 @@
end
end
end
end

seed do
p1_id = relations[:puzzles].insert(text: 'P1')
p2_id = relations[:puzzles].insert(text: 'P2', solved: true)
p3_id = relations[:puzzles].insert(text: 'P3')
Expand Down
Loading