Skip to content

Commit

Permalink
Merge pull request #229 from ifad/chore/minor-fixes
Browse files Browse the repository at this point in the history
Minor cosmetic improvements
  • Loading branch information
tagliala authored Sep 22, 2023
2 parents c6c9cc9 + cdd2f04 commit dfddf74
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
10 changes: 3 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ Rails/SkipsModelValidations:
Rails/TimeZone:
Enabled: false

RSpec/BeforeAfterAll:
Exclude:
- 'spec/support/adapter/helpers.rb'

RSpec/ExampleLength:
Enabled: false

Expand All @@ -83,11 +79,11 @@ Style/GlobalVars:
Exclude:
- 'spec/**/*'

Style/IfUnlessModifier:
Enabled: false

# NOTE: This cop is enabled by RuboCop Rails, because active support adds this
# method to hash, but `except` is not available in specs
Style/HashExcept:
Exclude:
- 'spec/**/*'

Style/IfUnlessModifier:
Enabled: false
2 changes: 1 addition & 1 deletion .rubocop_todo.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions lib/chrono_model/adapter/ddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def chrono_public_view_ddl(table, options = nil)
# Set default values on the view (closes #12)
#
columns(table).each do |column|
default = if column.default.nil?
column.default_function
else
quote(column.default)
end
default =
if column.default.nil?
column.default_function
else
quote(column.default)
end

next if column.name == pk || default.nil?

Expand Down Expand Up @@ -117,18 +118,19 @@ def chrono_create_INSERT_trigger(table, pk, current, history, fields, values)
def chrono_create_UPDATE_trigger(table, pk, current, history, fields, values, options, columns)
# Columns to be journaled. By default everything except updated_at (GH #7)
#
journal = if options[:journal]
options[:journal].map { |col| quote_column_name(col) }
journal =
if options[:journal]
options[:journal].map { |col| quote_column_name(col) }

elsif options[:no_journal]
columns - options[:no_journal].map { |col| quote_column_name(col) }
elsif options[:no_journal]
columns - options[:no_journal].map { |col| quote_column_name(col) }

elsif options[:full_journal]
columns
elsif options[:full_journal]
columns

else
columns - [quote_column_name('updated_at')]
end
else
columns - [quote_column_name('updated_at')]
end

journal &= columns

Expand Down
25 changes: 13 additions & 12 deletions lib/chrono_model/time_machine/time_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ def primitive_type_for_column(column)
end

def build_time_query_at(time, range)
time = if time.is_a?(Array)
time.map! { |t| time_for_time_query(t, range) }
time =
if time.is_a?(Array)
time.map! { |t| time_for_time_query(t, range) }

# If both edges of the range are the same the query fails using the '&&' operator.
# The correct solution is to use the <@ operator.
if time.first == time.last
time.first
else
time
end
else
time_for_time_query(time, range)
end
# If both edges of the range are the same the query fails using the '&&' operator.
# The correct solution is to use the <@ operator.
if time.first == time.last
time.first
else
time
end
else
time_for_time_query(time, range)
end

build_time_query(time, range)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/chrono_model/adapter/ddl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
include ChronoTest::Adapter::Helpers
include ChronoTest::Adapter::Structure

let(:current) { [ChronoModel::Adapter::TEMPORAL_SCHEMA, table].join('.') }
let(:history) { [ChronoModel::Adapter::HISTORY_SCHEMA, table].join('.') }
let(:current) { "#{ChronoModel::Adapter::TEMPORAL_SCHEMA}.#{table}" }
let(:history) { "#{ChronoModel::Adapter::HISTORY_SCHEMA}.#{table}" }

def count(table)
adapter.select_value("SELECT COUNT(*) FROM ONLY #{table}").to_i
Expand Down
6 changes: 3 additions & 3 deletions spec/chrono_model/time_machine/timestamps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let(:record) { $t.foo.history.first }

(history_methods + current_methods).each do |attr|
describe ['#', attr].join do
describe "##{attr}" do
subject { record.public_send(attr) }

it { is_expected.to be_present }
Expand All @@ -27,15 +27,15 @@
let(:record) { $t.foo }

history_methods.each do |attr|
describe ['#', attr].join do
describe "##{attr}" do
subject(:attribute) { record.public_send(attr) }

it { expect { attribute }.to raise_error(NoMethodError) }
end
end

current_methods.each do |attr|
describe ['#', attr].join do
describe "##{attr}" do
subject { record.public_send(attr) }

it { is_expected.to be_nil }
Expand Down
11 changes: 6 additions & 5 deletions spec/support/adapter/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def self.columns(&block)
end

def self.pk_type
@pk_type ||= if ActiveRecord::VERSION::STRING.to_f >= 5.1
'bigint'
else
'integer'
end
@pk_type ||=
if ActiveRecord::VERSION::STRING.to_f >= 5.1
'bigint'
else
'integer'
end
end
delegate :columns, :table, :pk_type, to: self
end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/matchers/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def has_history_indexes?
AND tablename = ?
SQL

fqtn = [history_schema, table].join('.')
fqtn = "#{history_schema}.#{table}"

expected = [
"CREATE INDEX index_#{table}_temporal_on_lower_validity ON #{fqtn} USING btree (lower(validity))",
Expand All @@ -169,7 +169,7 @@ def has_consistency_constraint?
binds = {
conname: connection.timeline_consistency_constraint_name(table),
connamespace: history_schema,
conrelid: [history_schema, table].join('.'),
conrelid: "#{history_schema}.#{table}",
attname: connection.primary_key(table)
}

Expand Down

0 comments on commit dfddf74

Please sign in to comment.