Skip to content

Commit

Permalink
uniqueness for announcement views
Browse files Browse the repository at this point in the history
Thanks, jhenkens
  • Loading branch information
csm123 committed Dec 9, 2014
1 parent 68b2532 commit bdbda3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/models/starburst/announcement_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ class AnnouncementView < ActiveRecord::Base
if Rails::VERSION::MAJOR < 4
attr_accessible :announcement, :user
end

belongs_to :announcement
belongs_to :user

validates :announcement_id, presence: true
validates :user_id, presence: true
validates_uniqueness_of :user_id, scope: :announcement_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddIndexAndUniquenessToAnnouncementViews < ActiveRecord::Migration
def change
add_index :starburst_announcement_views, [:user_id, :announcement_id], unique: true, name: 'starburst_announcement_view_index'
end
end
5 changes: 5 additions & 0 deletions spec/factories/announcement_views.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :announcement_view, class: Starburst::AnnouncementView do

end
end

0 comments on commit bdbda3a

Please sign in to comment.