Skip to content

Commit

Permalink
Rename total seats counter for events, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zonque committed Apr 21, 2024
1 parent 4388f73 commit 33bffcd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/admin/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
row :created_at
row :updated_at
row :confirmed_at
row :entries_added
row :seats_added_total
row :current_entries do |event|
event.entries.count
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def show
description: @event.description,
end_date: @event.end_date,
entries_current: @event.entries.confirmed.count,
entries_added_total: @event.entries_added
seats_added_total: @event.seats_added_total
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def self.ransackable_attributes(auth_object = nil)
end

def increase_event_entries_count
event.increment!(:entries_added)
event.increment!(:seats_added_total, self.seats)
end

def create_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.ransackable_associations(auth_object = nil)

def self.ransackable_attributes(auth_object = nil)
["admin_email", "admin_token", "confirmed_at", "created_at", "description",
"end_date", "id", "id_value", "name", "shadow_banned", "updated_at", "entries_added"]
"end_date", "id", "id_value", "name", "shadow_banned", "updated_at", "seats_added_total"]
end

def create_id
Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb

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

11 changes: 11 additions & 0 deletions test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ class EventsControllerTest < ActionDispatch::IntegrationTest
assert @response.body.include?("error")
end

define_method("test_should_get_json_for_event_#{locale}") do
e = events(:one)

get event_url(e, format: :json, locale: locale)

assert_response :success
assert @response.headers["Content-Type"].include?("application/json")
assert @response.body.include?(e.name)
assert @response.body.include?(e.seats_added_total.to_s)
end

define_method("test_should_get_redirect_to_root_for_a_non-existing_event_#{locale}") do
get event_url("non-existing", locale: locale)
assert_redirected_to root_path(locale: locale)
Expand Down
10 changes: 10 additions & 0 deletions test/models/entry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ class EntryTest < ActiveSupport::TestCase
assert entry.id.present?
assert entry.token.present?
end

test "controller should increment seats_added_total" do
event = events(:one)
entry = entries(:rwt1)

assert_difference("event.seats_added_total", 5) do
Entry.create!(entry.attributes.merge(event_id: event.id, seats: 5))
assert event.reload
end
end
end

0 comments on commit 33bffcd

Please sign in to comment.