From 528a5ce32c32aa9b6b2cfa1c58c8b4657afe9b6d Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 16 Feb 2013 00:28:31 +1100 Subject: [PATCH] changed to/from to recipient/sender --- app/models/ability.rb | 4 ++-- app/models/comment.rb | 4 ++-- app/models/member.rb | 4 ++-- app/models/notification.rb | 6 +++--- app/views/notifications/index.html.haml | 4 ++-- app/views/notifications/show.html.haml | 4 ++-- .../20130215131921_rename_notification_fields.rb | 8 ++++++++ db/schema.rb | 10 +++++----- spec/controllers/notifications_controller_spec.rb | 2 +- spec/views/notifications/index.html.haml_spec.rb | 8 ++++---- spec/views/notifications/show.html.haml_spec.rb | 4 ++-- 11 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 db/migrate/20130215131921_rename_notification_fields.rb diff --git a/app/models/ability.rb b/app/models/ability.rb index 581924f1c..3b90ffa56 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -13,8 +13,8 @@ class Ability can :update, Member, :id => member.id # can read/delete notifications that were sent to them - can :read, Notification, :to_id => member.id - can :destroy, Notification, :to_id => member.id + can :read, Notification, :recipient_id => member.id + can :destroy, Notification, :recipient_id => member.id # note we don't support create/update for notifications # for now, anyone can create/edit/destroy crops diff --git a/app/models/comment.rb b/app/models/comment.rb index 813d5a1af..24071bd0f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -5,8 +5,8 @@ class Comment < ActiveRecord::Base after_create { Notification.create( - :to_id => self.post.author.id, - :from_id => self.author.id, + :recipient_id => self.post.author.id, + :sender_id => self.author.id, :subject => "New comment on #{self.post.subject}", :body => self.body, :post_id => self.post.id diff --git a/app/models/member.rb b/app/models/member.rb index 4f8b11413..5d6cbdf19 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -5,8 +5,8 @@ class Member < ActiveRecord::Base has_many :posts, :foreign_key => 'author_id' has_many :comments, :foreign_key => 'author_id' has_many :gardens, :foreign_key => 'owner_id' - has_many :notifications, :foreign_key => 'to_id' - has_many :sent_notifications, :foreign_key => 'from_id' + has_many :notifications, :foreign_key => 'recipient_id' + has_many :sent_notifications, :foreign_key => 'sender_id' # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, diff --git a/app/models/notification.rb b/app/models/notification.rb index 782f8bff7..3202546f2 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,9 +1,9 @@ class Notification < ActiveRecord::Base - attr_accessible :to_id, :from_id, + attr_accessible :sender_id, :recipient_id, :subject, :body, :post_id, :read - belongs_to :sender, :class_name => 'Member', :foreign_key => 'from_id' - belongs_to :recipient, :class_name => 'Member', :foreign_key => 'to_id' + belongs_to :sender, :class_name => 'Member' + belongs_to :recipient, :class_name => 'Member' belongs_to :post end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index c5ddc573d..9479ccdb3 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -14,8 +14,8 @@ - @notifications.each do |notification| %tr - %td= notification.from_id - %td= notification.to_id + %td= notification.sender_id + %td= notification.recipient_id %td= notification.subject %td= notification.body %td= notification.read diff --git a/app/views/notifications/show.html.haml b/app/views/notifications/show.html.haml index 9a0657294..8884d5be7 100644 --- a/app/views/notifications/show.html.haml +++ b/app/views/notifications/show.html.haml @@ -2,10 +2,10 @@ %p %b From: - = @notification.from_id + = @notification.sender_id %p %b To: - = @notification.to_id + = @notification.recipient_id %p %b Subject: = @notification.subject diff --git a/db/migrate/20130215131921_rename_notification_fields.rb b/db/migrate/20130215131921_rename_notification_fields.rb new file mode 100644 index 000000000..63f52ae6d --- /dev/null +++ b/db/migrate/20130215131921_rename_notification_fields.rb @@ -0,0 +1,8 @@ +class RenameNotificationFields < ActiveRecord::Migration + def change + change_table :notifications do |t| + t.rename :to_id, :recipient_id + t.rename :from_id, :sender_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a7eb7dd65..daa18b758 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130212123628) do +ActiveRecord::Schema.define(:version => 20130215131921) do create_table "comments", :force => true do |t| t.integer "post_id", :null => false @@ -77,14 +77,14 @@ ActiveRecord::Schema.define(:version => 20130212123628) do add_index "members", ["unlock_token"], :name => "index_users_on_unlock_token", :unique => true create_table "notifications", :force => true do |t| - t.integer "from_id" - t.integer "to_id", :null => false + t.integer "sender_id" + t.integer "recipient_id", :null => false t.string "subject" t.text "body" t.boolean "read" t.integer "post_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "plantings", :force => true do |t| diff --git a/spec/controllers/notifications_controller_spec.rb b/spec/controllers/notifications_controller_spec.rb index 48b277c2d..b62dfad83 100644 --- a/spec/controllers/notifications_controller_spec.rb +++ b/spec/controllers/notifications_controller_spec.rb @@ -5,7 +5,7 @@ describe NotificationsController do login_member def valid_attributes - { "to_id" => subject.current_member.id } + { "recipient_id" => subject.current_member.id } end def valid_session diff --git a/spec/views/notifications/index.html.haml_spec.rb b/spec/views/notifications/index.html.haml_spec.rb index 171a0f69d..6a653f8bf 100644 --- a/spec/views/notifications/index.html.haml_spec.rb +++ b/spec/views/notifications/index.html.haml_spec.rb @@ -4,16 +4,16 @@ describe "notifications/index" do before(:each) do assign(:notifications, [ stub_model(Notification, - :from_id => 1, - :to_id => 2, + :sender_id => 1, + :recipient_id => 2, :subject => "Subject", :body => "MyText", :read => false, :post_id => 4 ), stub_model(Notification, - :from_id => 1, - :to_id => 2, + :sender_id => 1, + :recipient_id => 2, :subject => "Subject", :body => "MyText", :read => false, diff --git a/spec/views/notifications/show.html.haml_spec.rb b/spec/views/notifications/show.html.haml_spec.rb index 49076c1d1..df087b014 100644 --- a/spec/views/notifications/show.html.haml_spec.rb +++ b/spec/views/notifications/show.html.haml_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe "notifications/show" do before(:each) do @notification = assign(:notification, stub_model(Notification, - :from_id => 1, - :to_id => 2, + :sender_id => 1, + :recipient_id => 2, :subject => "Subject", :body => "MyText", :read => false,