Skip to content

Commit

Permalink
Code tidy-up
Browse files Browse the repository at this point in the history
- removed event scopes that are on event instance
- removed dead code
- removed some other bits
  • Loading branch information
ivankocienski committed Sep 18, 2024
1 parent a06f805 commit 1f649fb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 164 deletions.
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def index
def show
@event_instance = EventInstance
.where( id: params[:id] )

Check failure on line 27 in app/controllers/events_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideParens: Space inside parentheses detected.

Check failure on line 27 in app/controllers/events_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideParens: Space inside parentheses detected.
#.joins(:event)
.first

Check failure on line 29 in app/controllers/events_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.
if @event_instance.blank?
@message = "Could not find event with that ID"
render 'home/not_found', status: :not_found

Check failure on line 32 in app/controllers/events_controller.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Expand Down
17 changes: 0 additions & 17 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,4 @@ def to_s
def address
@address ||= EventAddress.new(self)
end

# needed ??

scope :from_day_onward, lambda { |epoch|
joins(:event_instances)
.where("date(event_instances.starts_at) >= date(?)", epoch)
}

scope :on_day, lambda { |day|
joins(:event_instances)
.where("date(event_instances.starts_at) = date(?)", day)
}

scope :before_date, lambda { |day|
joins(:event_instances)
.where("date(event_instances.starts_at) < date(?)", day)
}
end
2 changes: 0 additions & 2 deletions app/views/events/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

%h1 Events

-# %p #{@events.count} events from #{@epoch.strftime('%A %e, %Y')}
.events-listing= render_event_by_day_list(@event_instances)
30 changes: 0 additions & 30 deletions lib/tasks/db_import.rake
Original file line number Diff line number Diff line change
Expand Up @@ -179,33 +179,3 @@ namespace :db do
end
end
end

__END__

def import_events
path = Rails.root.join('db/fixtures/events.json')
puts "Importing events from #{path}"

data = JSON.parse(File.open(path).read)
data['data']['eventsByFilter'].each do |event_data|
organizer_id = event_data['organizer']['id'].to_i

partner = @partners_by_placecal_id[organizer_id]
raise "import_events: partner not found for organizer #{organizer_id}" if partner.blank?

event_data['address'] ||= {}

partner.events.create!(
placecal_id: event_data['id'],
name: event_data['name'],
summary: event_data['summary'],
description: event_data['description'],
starts_at: Time.zone.parse(event_data['startDate']),
ends_at: Time.zone.parse(event_data['endDate']),
organizer_placecal_id: organizer_id,
address_street: event_data['address']['streetAddress'],
address_postcode: event_data['address']['postalCode']
)

end
end
53 changes: 0 additions & 53 deletions spec/integration/event_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,56 +50,3 @@ def create_events_for_partner(count, id_offset, time_offset)
end
end
end


__END__

4.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY,
placecal_id: 200 + n
)
end
2.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 1.day,
placecal_id: 300 + n
)
end
3.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 2.days,
placecal_id: 400 + n
)
end
1.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 3.days,
placecal_id: 500 + n
)
end
4.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 4.days,
placecal_id: 600 + n
)
end
5.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 5.days,
placecal_id: 700 + n
)
end
1.times do |n|
partner.events.create!(
name: 'Alpha',
starts_at: FakeTime::TODAY + 6.days,
placecal_id: 800 + n
)
end
57 changes: 56 additions & 1 deletion spec/models/event_instance_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
require 'rails_helper'

RSpec.describe EventInstance, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
context '(date scope)' do
def create_event(start, placecal_id, partner)
Event.transaction do

event = Event.create! partner: partner
event.event_instances.create!(
starts_at: start,
placecal_id: placecal_id
)
end
end

before :each do
partner = Partner.create! name: 'Alpha', placecal_id: 200

# 1st of june
create_event Time.new(2000, 6, 1, 10, 30), 100, partner
create_event Time.new(2000, 6, 1, 12, 30), 100, partner

# 4th of june
create_event Time.new(2000, 6, 4, 9, 0), 100, partner
create_event Time.new(2000, 6, 4, 12, 0), 100, partner
create_event Time.new(2000, 6, 4, 17, 30), 100, partner

# 10th of june
create_event Time.new(2000, 6, 10, 8, 0), 100, partner
create_event Time.new(2000, 6, 10, 10, 0), 100, partner

# 1st of july
create_event Time.new(2000, 7, 1, 10, 30), 100, partner
end

# june 4th at 4.25pm
let(:epoch) { Time.new(2000, 6, 4, 16, 25) }

context '::from_day_onward' do
it 'returns events in future of epoch (including all events on same day)' do
found = EventInstance.from_day_onward(epoch)
expect(found.count).to eq 6
end
end

context '::on_day' do
it 'returns events only on that day' do
found = EventInstance.on_day(epoch)
expect(found.count).to eq 3
end
end

context '::before_date' do
it 'returns all events *before* date' do
found = EventInstance.before_date(epoch)
expect(found.count).to eq 2
end
end
end
end
60 changes: 0 additions & 60 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
require 'rails_helper'

RSpec.describe Event, type: :model do

context '(date scope)' do
def create_event(start, placecal_id, partner)
Event.transaction do

event = Event.create! partner: partner
event.event_instances.create!(
starts_at: start,
placecal_id: placecal_id
)
end
end

before :each do
partner = Partner.create! name: 'Alpha', placecal_id: 200

# 1st of june
create_event Time.new(2000, 6, 1, 10, 30), 100, partner
create_event Time.new(2000, 6, 1, 12, 30), 100, partner

# 4th of june
create_event Time.new(2000, 6, 4, 9, 0), 100, partner
create_event Time.new(2000, 6, 4, 12, 0), 100, partner
create_event Time.new(2000, 6, 4, 17, 30), 100, partner

# 10th of june
create_event Time.new(2000, 6, 10, 8, 0), 100, partner
create_event Time.new(2000, 6, 10, 10, 0), 100, partner

# 1st of july
create_event Time.new(2000, 7, 1, 10, 30), 100, partner
end

# june 4th at 4.25pm
let(:epoch) { Time.new(2000, 6, 4, 16, 25) }

context '::from_day_onward' do
it 'returns events in future of epoch (including all events on same day)' do
found = Event.from_day_onward(epoch)
expect(found.count).to eq 6
end
end

context '::on_day' do
it 'returns events only on that day' do
found = Event.on_day(epoch)
expect(found.count).to eq 3
end
end

context '::before_date' do
it 'returns all events *before* date' do
found = Event.before_date(epoch)
expect(found.count).to eq 2
end
end



end
end

0 comments on commit 1f649fb

Please sign in to comment.