-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
105 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
class Group < ActiveRecord::Base | ||
resourcify | ||
|
||
has_many :user_group_memberships | ||
has_many :users, through: :user_group_memberships | ||
|
||
has_many :game_nights | ||
|
||
belongs_to :moderator, class_name: :User, foreign_key: :moderator_id | ||
|
||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Role < ActiveRecord::Base | ||
has_and_belongs_to_many :users, join_table: :users_roles | ||
belongs_to :resource, polymorphic: true | ||
|
||
validates :resource_type, | ||
inclusion: { in: Rolify.resource_types }, | ||
allow_nil: true | ||
|
||
scopify | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class User < ActiveRecord::Base | ||
rolify | ||
has_secure_password | ||
|
||
has_many :user_group_memberships | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Rolify.configure do |config| | ||
# By default ORM adapter is ActiveRecord. uncomment to use mongoid | ||
# config.use_mongoid | ||
|
||
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false | ||
# config.use_dynamic_shortcuts | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class RolifyCreateRoles < ActiveRecord::Migration | ||
def change | ||
create_table(:roles) do |t| | ||
t.string :name | ||
t.references :resource, :polymorphic => true | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table(:users_roles, :id => false) do |t| | ||
t.references :user | ||
t.references :role | ||
end | ||
|
||
add_index(:roles, :name) | ||
add_index(:roles, [ :name, :resource_type, :resource_id ]) | ||
add_index(:users_roles, [ :user_id, :role_id ]) | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20160123223259_remove_organizer_id_from_game_nights.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveOrganizerIdFromGameNights < ActiveRecord::Migration | ||
def change | ||
remove_column :game_nights, :organizer_id, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveModeratorIdFromGroups < ActiveRecord::Migration | ||
def change | ||
remove_column :groups, :moderator_id, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | ||
# Mayor.create(name: 'Emanuel', city: cities.first) | ||
require 'faker' | ||
|
||
# create users | ||
5.times do | ||
User.create(first_name: Faker::Name.first_name, | ||
last_name: Faker::Name.last_name, | ||
email: Faker::Internet.email, | ||
city: Faker::Address.city, | ||
state: Faker::Address.state, | ||
country: Faker::Address.country, | ||
password: "helloworld", | ||
email_confirmed: true) | ||
end | ||
|
||
# create game_night | ||
5.times do | ||
GameNight.create(name: Faker::Hipster.words(2), | ||
time: rand(7).days.from_now.to_date, | ||
location_name: Faker::Hipster.words(2), | ||
location_address: Faker::Address.street_name) | ||
end | ||
|
||
# create groups | ||
5.times do | ||
Group.create(name: Faker::Hipster.words(2)) | ||
end | ||
|
||
puts "#{User.count} Users created" | ||
puts "#{GameNight.count} GameNights created" | ||
puts "#{Group.count} Groups created" |