Skip to content

Commit

Permalink
Merge pull request #99 from co-cddo/order-agreements-in-power-show-view
Browse files Browse the repository at this point in the history
Order agreements in power show view
  • Loading branch information
RobNicholsGDS authored Nov 5, 2024
2 parents 49df8fe + 0c64bdf commit 5322105
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/agreement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Agreement < DataTable
self.rapid_table_name = :agreements
self.rapid_name_field = :agreement_name

default_scope { order(Arel.sql("(fields ->> 'ID')::Integer")) }
default_scope { order(Arel.sql("CAST(record_id AS Integer)")) }

has_many :power_agreements, dependent: :delete_all
has_many :powers, through: :power_agreements
Expand Down
3 changes: 2 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.data_source = ENV.fetch("DATA_SOURCE", :airtable).to_sym
# Data source options are :airtable and :rapid
config.data_source = ENV.fetch("DATA_SOURCE", :rapid).to_sym
end
end
2 changes: 1 addition & 1 deletion spec/factories/agreements.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :agreement do
name { Faker::Name.name }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
sequence :fields do |n|
{ name:, id: n }
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/air_table_tables.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryBot.define do
factory :air_table_table do
name { Faker::Company.name }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
end
end
2 changes: 1 addition & 1 deletion spec/factories/control_people.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :control_person do
name { Faker::Name.name }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
fields { { name: } }
end
end
2 changes: 1 addition & 1 deletion spec/factories/data_tables.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :data_table do
name { Faker::Company.industry }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
type { %w[Agreement Power ControlPerson].sample }

# NOTE: DataTable is an abstract (STI) class
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/powers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :power do
name { Faker::Name.name }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
fields { { status: "active", name: } }

trait :retired do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/processors.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :processor do
name { Faker::Name.name }
record_id { SecureRandom.uuid }
record_id { rand(1..100) }
fields { { name: } }
end
end
4 changes: 4 additions & 0 deletions spec/models/agreement_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
agreement
end

before do
allow(Rails.configuration).to receive(:data_source).and_return(:airtable)
end

it "creates a new instance" do
expect { populate }.to change(described_class, :count).by(1)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/agreement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

context "with rAPId source" do
let(:controller_name) { Faker::Name.name }
let(:id) { SecureRandom.uuid }
let(:id) { rand(0..1).to_s }
let(:data) do
{
1 => {
Expand Down
4 changes: 4 additions & 0 deletions spec/models/power_agreement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
agreement
end

before do
allow(Rails.configuration).to receive(:data_source).and_return(:airtable)
end

it "creates a PowerAgreement" do
expect { populate }.to change(described_class, :count).by(1)
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/power_control_person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
power
end

before do
allow(Rails.configuration).to receive(:data_source).and_return(:airtable)
end

it "creates a PowerAgreement" do
expect { populate }.to change(described_class, :count).by(1)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/shared_examples/is_data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
subject(:populate) { described_class.populate }

let(:name) { Faker::Name.name }
let(:id) { SecureRandom.uuid }
let(:id) { rand(0..100).to_s }

context "with rAPId source" do
let(:data) do
Expand Down Expand Up @@ -113,7 +113,7 @@

# A second call is then triggered and that needs to return a different set of data
# As this is then the last set of data, it does not include an offset
let(:offset_id) { SecureRandom.uuid }
let(:offset_id) { rand(1..100).to_s }
let(:offset_data) do
{
records: [{
Expand Down

0 comments on commit 5322105

Please sign in to comment.