<%= richtext_area :diary_comment, :body, :cols => 80, :rows => 15 %>
<%= submit_tag t('diary_entry.view.save_button') %>
<% end %>
- <% if @user and @entry.subscribers and @entry.subscribers.exists?(@user.id) %>
+ <% if @user and @entry.subscribers.exists?(@user.id) %>
<div class="diary-subscribe-buttons"><%= link_to t('javascripts.changesets.show.unsubscribe'), diary_entry_unsubscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
<% elsif @user %>
<div class="diary-subscribe-buttons"><%= link_to t('javascripts.changesets.show.subscribe'), diary_entry_subscribe_path(:display_name => @entry.user.display_name, :id => @entry.id), :method => :post, :class => :button %></div>
+require "migrate"
+
class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
- def change
+ def self.up
create_table :diary_entry_subscriptions, :id => false do |t|
t.column :user_id, :bigint, :null => false
t.column :diary_entry_id, :bigint, :null => false
end
- add_index :diary_entry_subscriptions, [:user_id, :diary_entry_id], :unique => true, :name => "index_diary_subscriptions_on_user_id_and_diary_entry_id"
+ add_primary_key :diary_entry_subscriptions, [:user_id, :diary_entry_id]
add_index :diary_entry_subscriptions, [:diary_entry_id]
+ add_foreign_key :diary_entry_subscriptions, :diary_entries, :name => "diary_entry_subscriptions_diary_entry_id_fkey"
+ add_foreign_key :diary_entry_subscriptions, :users, :name => "diary_entry_subscriptions_user_id_fkey"
+ end
+
+ def self.down
+ drop_table :diary_entry_subscriptions
end
end
diary_entry = create(:diary_entry, :user_id => users(:normal_user).id)
# not signed in
- assert_no_difference "diary_entry.subscribers.count", 1 do
+ assert_no_difference "diary_entry.subscribers.count" do
post :subscribe, :id => diary_entry.id, :display_name => diary_entry.user.display_name
end
assert_response :forbidden