mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
age_range & theme for event model
This commit is contained in:
parent
4d4248bcca
commit
cbbd697d38
3
app/models/age_range.rb
Normal file
3
app/models/age_range.rb
Normal file
@ -0,0 +1,3 @@
|
||||
class AgeRange < ActiveRecord::Base
|
||||
has_many :events
|
||||
end
|
@ -8,6 +8,9 @@ class Event < ActiveRecord::Base
|
||||
has_and_belongs_to_many :categories, join_table: :events_categories
|
||||
validates :categories, presence: true
|
||||
has_many :reservations, as: :reservable, dependent: :destroy
|
||||
has_and_belongs_to_many :event_themes, join_table: :events_event_themes
|
||||
|
||||
belongs_to :age_range
|
||||
|
||||
belongs_to :availability, dependent: :destroy
|
||||
accepts_nested_attributes_for :availability
|
||||
@ -23,6 +26,10 @@ class Event < ActiveRecord::Base
|
||||
title
|
||||
end
|
||||
|
||||
def themes
|
||||
self.event_themes
|
||||
end
|
||||
|
||||
def recurrence_events
|
||||
Event.includes(:availability).where('events.recurrence_id = ? AND events.id != ? AND availabilities.start_at >= ?', recurrence_id, id, Time.now).references(:availabilities)
|
||||
end
|
||||
|
2
app/models/event_theme.rb
Normal file
2
app/models/event_theme.rb
Normal file
@ -0,0 +1,2 @@
|
||||
class EventTheme < ActiveRecord::Base
|
||||
end
|
9
db/migrate/20160628124538_create_event_themes.rb
Normal file
9
db/migrate/20160628124538_create_event_themes.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class CreateEventThemes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :event_themes do |t|
|
||||
t.string :name
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
8
db/migrate/20160628131408_create_events_event_themes.rb
Normal file
8
db/migrate/20160628131408_create_events_event_themes.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class CreateEventsEventThemes < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :events_event_themes do |t|
|
||||
t.belongs_to :event, index: true, foreign_key: true
|
||||
t.belongs_to :event_theme, index: true, foreign_key: true
|
||||
end
|
||||
end
|
||||
end
|
9
db/migrate/20160628134211_create_age_ranges.rb
Normal file
9
db/migrate/20160628134211_create_age_ranges.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class CreateAgeRanges < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :age_ranges do |t|
|
||||
t.string :range
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
5
db/migrate/20160628134303_add_age_range_id_to_event.rb
Normal file
5
db/migrate/20160628134303_add_age_range_id_to_event.rb
Normal file
@ -0,0 +1,5 @@
|
||||
class AddAgeRangeIdToEvent < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :events, :age_range_id, :integer
|
||||
end
|
||||
end
|
25
db/schema.rb
25
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
ActiveRecord::Schema.define(version: 20160628134303) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -44,6 +44,12 @@ ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "age_ranges", force: :cascade do |t|
|
||||
t.string "range"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "assets", force: :cascade do |t|
|
||||
t.integer "viewable_id"
|
||||
t.string "viewable_type", limit: 255
|
||||
@ -114,6 +120,12 @@ ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "event_themes", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "events", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.text "description"
|
||||
@ -125,6 +137,7 @@ ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
t.integer "nb_total_places"
|
||||
t.integer "nb_free_places"
|
||||
t.integer "recurrence_id"
|
||||
t.integer "age_range_id"
|
||||
end
|
||||
|
||||
add_index "events", ["availability_id"], name: "index_events_on_availability_id", using: :btree
|
||||
@ -140,6 +153,14 @@ ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
add_index "events_categories", ["category_id"], name: "index_events_categories_on_category_id", using: :btree
|
||||
add_index "events_categories", ["event_id"], name: "index_events_categories_on_event_id", using: :btree
|
||||
|
||||
create_table "events_event_themes", force: :cascade do |t|
|
||||
t.integer "event_id"
|
||||
t.integer "event_theme_id"
|
||||
end
|
||||
|
||||
add_index "events_event_themes", ["event_id"], name: "index_events_event_themes_on_event_id", using: :btree
|
||||
add_index "events_event_themes", ["event_theme_id"], name: "index_events_event_themes_on_event_theme_id", using: :btree
|
||||
|
||||
create_table "friendly_id_slugs", force: :cascade do |t|
|
||||
t.string "slug", limit: 255, null: false
|
||||
t.integer "sluggable_id", null: false
|
||||
@ -678,6 +699,8 @@ ActiveRecord::Schema.define(version: 20160628092931) do
|
||||
|
||||
add_foreign_key "availability_tags", "availabilities"
|
||||
add_foreign_key "availability_tags", "tags"
|
||||
add_foreign_key "events_event_themes", "event_themes"
|
||||
add_foreign_key "events_event_themes", "events"
|
||||
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
||||
add_foreign_key "open_api_calls_count_tracings", "open_api_clients"
|
||||
add_foreign_key "prices", "groups"
|
||||
|
13
test/fixtures/age_ranges.yml
vendored
Normal file
13
test/fixtures/age_ranges.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
youngs:
|
||||
id: 1
|
||||
range: De 10 à 21 ans
|
||||
|
||||
adults:
|
||||
id: 2
|
||||
range: A partir de 18 ans
|
||||
|
||||
seniors:
|
||||
id: 3
|
||||
range: A partir de 65 ans
|
7
test/fixtures/event_themes.yml
vendored
Normal file
7
test/fixtures/event_themes.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
diy:
|
||||
id: 1
|
||||
name: Do it yourself
|
||||
|
||||
robot:
|
||||
id: 2
|
||||
name: Robot
|
1
test/fixtures/events.yml
vendored
1
test/fixtures/events.yml
vendored
@ -12,6 +12,7 @@ event_2:
|
||||
nb_total_places: 10
|
||||
nb_free_places: 10
|
||||
recurrence_id: 1
|
||||
age_range_id: 2
|
||||
|
||||
event_3:
|
||||
id: 3
|
||||
|
5
test/fixtures/events_event_themes.yml
vendored
Normal file
5
test/fixtures/events_event_themes.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
events_event_themes_1:
|
||||
id: 1
|
||||
event_id: 1
|
||||
event_theme_id: 1
|
23
test/models/event_test.rb
Normal file
23
test/models/event_test.rb
Normal file
@ -0,0 +1,23 @@
|
||||
require 'test_helper'
|
||||
|
||||
class EventTest < ActiveSupport::TestCase
|
||||
test 'event must have a category' do
|
||||
e = Event.first
|
||||
assert_not_nil e.categories.first
|
||||
end
|
||||
|
||||
test 'event must have a theme' do
|
||||
e = Event.find(1)
|
||||
assert_not_empty e.themes
|
||||
end
|
||||
|
||||
test 'event must have an age range' do
|
||||
e = Event.find(2)
|
||||
assert_not_nil e.age_range.range
|
||||
end
|
||||
|
||||
test 'event must not have any age range' do
|
||||
e = Event.find(3)
|
||||
assert_nil e.age_range
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user