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

#77 validation added. parent presence validation, title presence, uniqueness... #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 9 additions & 6 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,30 @@ def index

def create
@project = Project.new(project_params)
@project.user_id = current_user.id


@project.user = current_user
@users = User.all
if @project.save
#associate_project_with_todos!
associate_project_with_assignees!

SlackNotifier.notify("프로젝트 추가되었어용 : #{@project.title} (#{Rails.application.routes.url_helpers.project_url(@project)})")
MailSender.send_email_when_create(current_user.email, @project)
redirect_to projects_path
else
flash[:error] = @project.errors.full_messages.join('\n')
render 'new'
end
redirect_to projects_path
end

def detail
@project = Project.find(params[:id])

end

def show
@todo = Todo.new
@todos = Todo.where(project_id: params[:id])
@histories = History.where(project_id: params[:id])

end

def edit
Expand All @@ -48,6 +49,7 @@ def edit

def update
@project = Project.find(params[:id])
@users = User.all

if @project.update(project_params)
#associate_project_with_todos!
Expand All @@ -56,6 +58,7 @@ def update
SlackNotifier.notify("프로젝트가 수정되었어용 : #{@project.title} (#{Rails.application.routes.url_helpers.project_url(@project)})")
redirect_to @project
else
flash[:error] = @project.errors.full_messages.join('\n')
render 'edit'
end
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :history

validates :contents, presence: true
validates :user, presence: true
end
4 changes: 4 additions & 0 deletions app/models/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class History < ActiveRecord::Base
has_many :inverse_history_histories, class_name: "HistoryHistory", foreign_key: "referencing_history_id"
has_many :referenced_histories, through: :inverse_history_histories, source: :history

validate :user, presence: true
validate :project, presence: true
validate :title, presence: true

include PublicActivity::Model
tracked :except => :destroy
has_many :activities, as: :trackable, class_name: 'PublicActivity::Activity', dependent: :destroy
Expand Down
7 changes: 5 additions & 2 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ class Project < ActiveRecord::Base
has_many :assignees, through: :project_users

belongs_to :user
has_many :todos
has_many :histories
has_many :todos, inverse_of: :project
has_many :histories, inverse_of: :project

validates :user, presence: true
validates :title, presence: true, uniqueness: { scope: :user }

def fetch_members_by_nickname(nickname, count)
members = assignees.arel_table
Expand Down
4 changes: 4 additions & 0 deletions app/models/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class Todo < ActiveRecord::Base
has_many :histories, through: :history_todos
belongs_to :user
belongs_to :project

validates :project, presence: true
validates :user, presence: true
validates :title, presence: true

def self.fetch_list_from(id, count)
where(arel_table[:id].gteq(id)).take(count)
Expand Down
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
has_many :histories
has_many :todos
has_many :histories, inverse_of: :user
has_many :todos, inverse_of: :user
has_many :projects, inverse_of: :user
has_many :comments, inverse_of: :user

has_many :history_users, foreign_key: :assignee_id
has_many :assigned_histories, through: :history_users
Expand All @@ -12,13 +14,11 @@ class User < ActiveRecord::Base

belongs_to :user

belongs_to :comment
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:facebook, :google_oauth2, :twitter]

validates_presence_of :nickname
validates_uniqueness_of :nickname
validates :nickname, uniqueness: true, presence: true

acts_as_reader

Expand Down