Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage and display members (#8) #74

Merged
merged 24 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/controllers/admin/members_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Admin
class MembersController < Admin::ApplicationController
# To customize the behavior of this controller,
# simply overwrite any of the RESTful actions. For example:
#
# def index
# super
# @resources = Member.all.paginate(10, params[:page])
# end

# Define a custom finder by overriding the `find_resource` method:
# def find_resource(param)
# Member.find_by!(slug: param)
# end

# See https://administrate-docs.herokuapp.com/customizing_controller_actions
# for more information
end
end
4 changes: 3 additions & 1 deletion app/dashboards/dashboard_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class DashboardManifest
:locations,
:jobs,
:organizations,
:pages
:pages,
:members,
#:users,
].freeze

# `ROOT_DASHBOARD`
Expand Down
62 changes: 62 additions & 0 deletions app/dashboards/member_dashboard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "administrate/base_dashboard"

class MemberDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.

events: Field::HasMany,
organizations: Field::HasMany,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After playing around to understand administrate and that bug: https://github.com/montrealrb/Montreal.rb/pull/74/files#r47185636

I found out that removing all references in the dashboard to events and organizations for now fixes it.

#user: Field::BelongsTo,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after #.

id: Field::Number,
name: Field::String,
email: Field::String,
picture: Field::String.with_options(searchable: false),
twitter_handle: Field::String,
github_handle: Field::String,
biography: Field::Text,
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze

# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.

:events,
:organizations,
#:user,
:id,
].freeze

# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys

# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.

:events,
:organizations,
#:user,
:name,
:email,
:picture,
:twitter_handle,
:github_handle,
:biography,
].freeze

# Overwrite this method to customize how members are displayed
# across all pages of the admin dashboard.
#
# def display_resource(member)
# "Member ##{member.id}"
# end
end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Event < ActiveRecord::Base
belongs_to :location
belongs_to :author, foreign_key: :user_id, class_name: "User"
has_many :talks, -> { where(state: "scheduled") }, class_name: "Talk"
has_and_belongs_to_many :members

to_param :title

Expand Down
8 changes: 8 additions & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Member < ActiveRecord::Base
has_and_belongs_to_many :events
has_and_belongs_to_many :organizations
belongs_to :user

validates :name, :email, presence: true
validates :email, uniqueness: true
end
2 changes: 2 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Organization < ActiveRecord::Base
has_many :jobs
has_and_belongs_to_many :jobs

translates :description
mount_uploader :logo, LogoUploader

Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ def self.default_user
def active_for_authentication?
super && email != DEFAULT_USER_EMAIL
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra empty line detected at class body end.

belongs_to :member
end
14 changes: 14 additions & 0 deletions db/migrate/20151125011253_create_members.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateMembers < ActiveRecord::Migration
def change
create_table :members do |t|
t.string :name
t.string :email
t.binary :picture
t.string :twitter_handle
t.string :github_handle
t.text :biography

t.timestamps null: false
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20151203012632_add_null_constraint_to_email.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNullConstraintToEmail < ActiveRecord::Migration
def change
change_column_null :members, :email, false
end
end
6 changes: 6 additions & 0 deletions db/migrate/20151203031902_add_foreign_key_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddForeignKeyToUsers < ActiveRecord::Migration
def change
add_column :users, :member_id, :integer
add_foreign_key :users, :members
end
end
6 changes: 6 additions & 0 deletions db/migrate/20151206020220_remove_foreign_key_from_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RemoveForeignKeyFromUsers < ActiveRecord::Migration
def change
remove_foreign_key :users, :members
remove_column :users, :member_id
end
end
6 changes: 6 additions & 0 deletions db/migrate/20151206044852_add_foreign_key_to_members.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddForeignKeyToMembers < ActiveRecord::Migration
def change
add_column :members, :user_id, :integer
add_foreign_key :members, :users
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateHabtmRelationshipBetweenMembersAndEvents < ActiveRecord::Migration
def change
create_table :events_members do |t|
t.belongs_to :event, index: true
t.belongs_to :member, index: true
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class HabtmRelationshipBetweenMembersAndOrganization < ActiveRecord::Migration
def change
create_table :members_organizations do |t|
t.belongs_to :organization, index: true
t.belongs_to :member, index: true
end
end
end
31 changes: 30 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160308004823) do
ActiveRecord::Schema.define(version: 20160310032845) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -41,6 +41,14 @@
add_index "events", ["starts_at"], name: "index_events_on_starts_at", using: :btree
add_index "events", ["user_id"], name: "index_events_on_user_id", using: :btree

create_table "events_members", force: :cascade do |t|
t.integer "event_id"
t.integer "member_id"
end

add_index "events_members", ["event_id"], name: "index_events_members_on_event_id", using: :btree
add_index "events_members", ["member_id"], name: "index_events_members_on_member_id", using: :btree

create_table "friendly_id_slugs", force: :cascade do |t|
t.string "slug", null: false
t.integer "sluggable_id", null: false
Expand Down Expand Up @@ -86,6 +94,26 @@
t.datetime "updated_at"
end

create_table "members", force: :cascade do |t|
t.string "name"
t.string "email", null: false
t.binary "picture"
t.string "twitter_handle"
t.string "github_handle"
t.text "biography"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end

create_table "members_organizations", force: :cascade do |t|
t.integer "organization_id"
t.integer "member_id"
end

add_index "members_organizations", ["member_id"], name: "index_members_organizations_on_member_id", using: :btree
add_index "members_organizations", ["organization_id"], name: "index_members_organizations_on_organization_id", using: :btree

create_table "news_items", force: :cascade do |t|
t.string "state"
t.datetime "published_at"
Expand Down Expand Up @@ -184,5 +212,6 @@
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
add_index "users", ["uid"], name: "index_users_on_uid", using: :btree

add_foreign_key "members", "users"
add_foreign_key "talks", "events"
end
4 changes: 2 additions & 2 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "rails_helper"

RSpec.describe EventsController, type: :controller do
let(:proposed_event) { create(:event, :proposed) }
let(:scheduled_event) { create(:event, :scheduled) }
let!(:proposed_event) { create(:event, :proposed) }
let!(:scheduled_event) { create(:event, :scheduled) }

describe "GET #index" do
before :each do
Expand Down
10 changes: 10 additions & 0 deletions spec/factories/members.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryGirl.define do
factory :member do
name "MyString"
email "MyString"
picture ""
twitter_handle "MyString"
github_handle "MyString"
biography "MyText"
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca we correct indentation here please?

39 changes: 39 additions & 0 deletions spec/models/member_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "rails_helper"

RSpec.describe Member, type: :model do
context "without a name" do
it "should be invalid" do
member = Member.new

member.email = "gala@example.com"

expect(member).to be_invalid
end
end

context "without an email" do
it "should be invalid" do
member = Member.new

member.name = "Zaba"

expect(member).to be_invalid
end
end

context "with a duplicate email" do
it "should be invalid" do
member1 = Member.new
member1.name = "Zaba"
member1.email = "gala@example.com"

member2 = Member.new
member2.name = "Gala"
member2.email = "gala@example.com"

member1.save

expect(member2).to be_invalid
end
end
end