diff options
author | Lukas Matt <lukas@zauberstuhl.de> | 2014-04-22 18:50:57 +0400 |
---|---|---|
committer | Lukas Matt <lukas@zauberstuhl.de> | 2014-05-15 15:23:44 +0400 |
commit | 218845d5b4e125ac64cc70c87e6b53f5ab09536f (patch) | |
tree | e8b426c933799868e15439c81b162549b7911a0a | |
parent | 8ae89a443b8599fdae13713088f54bc926199d61 (diff) |
Changed and renamed database columns
* changed user_id type to integer
* renamed post_id to item_id
* renamed post_type to item_type
-rw-r--r-- | app/assets/javascripts/app/views.js | 4 | ||||
-rw-r--r-- | app/controllers/report_controller.rb | 2 | ||||
-rw-r--r-- | app/models/report.rb | 18 | ||||
-rw-r--r-- | app/views/report/index.html.haml | 9 | ||||
-rw-r--r-- | db/migrate/20140422134050_rename_post_columns_to_item.rb | 11 | ||||
-rw-r--r-- | db/migrate/20140422134627_change_user_id_type_to_integer.rb | 9 | ||||
-rw-r--r-- | db/migrate/20140422135040_drop_table_post_reports.rb | 9 | ||||
-rw-r--r-- | db/schema.rb | 21 | ||||
-rw-r--r-- | spec/controllers/report_controller_spec.rb | 26 | ||||
-rw-r--r-- | spec/models/report_spec.rb | 14 |
10 files changed, 71 insertions, 52 deletions
diff --git a/app/assets/javascripts/app/views.js b/app/assets/javascripts/app/views.js index e0f41e553..78baa19b7 100644 --- a/app/assets/javascripts/app/views.js +++ b/app/assets/javascripts/app/views.js @@ -89,8 +89,8 @@ app.views.Base = Backbone.View.extend({ } var data = { report: { - post_id: this.model.id, - post_type: $(evt.currentTarget).data("type"), + item_id: this.model.id, + item_type: $(evt.currentTarget).data("type"), text: msg } }; diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb index 42312c88e..64022d988 100644 --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -37,6 +37,6 @@ class ReportController < ApplicationController private def report_params - params.require(:report).permit(:post_id, :post_type, :text) + params.require(:report).permit(:item_id, :item_type, :text) end end diff --git a/app/models/report.rb b/app/models/report.rb index e934e216d..358704009 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -1,7 +1,7 @@ class Report < ActiveRecord::Base validates :user_id, presence: true - validates :post_id, presence: true - validates :post_type, presence: true + validates :item_id, presence: true + validates :item_type, presence: true validates :text, presence: true validate :entry_does_not_exist, :on => :create @@ -13,22 +13,22 @@ class Report < ActiveRecord::Base after_commit :send_report_notification, :on => :create def entry_does_not_exist - if Report.where(post_id: post_id, post_type: post_type).exists?(user_id: user_id) + if Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) errors[:base] << 'You cannot report the same post twice.' end end def destroy_reported_item - if post_type == 'post' + if item_type == 'post' delete_post - elsif post_type == 'comment' + elsif item_type == 'comment' delete_comment end mark_as_reviewed end def delete_post - if post = Post.where(id: post_id).first + if post = Post.where(id: item_id).first if post.author.local? post.author.owner.retract(post) else @@ -38,7 +38,7 @@ class Report < ActiveRecord::Base end def delete_comment - if comment = Comment.where(id: post_id).first + if comment = Comment.where(id: item_id).first if comment.author.local? comment.author.owner.retract(comment) elsif comment.parent.author.local? @@ -50,10 +50,10 @@ class Report < ActiveRecord::Base end def mark_as_reviewed - Report.where(post_id: post_id, post_type: post_type).update_all(reviewed: true) + Report.where(item_id: item_id, item_type: item_type).update_all(reviewed: true) end def send_report_notification - Workers::Mail::ReportWorker.perform_async(self.post_type, self.post_id) + Workers::Mail::ReportWorker.perform_async(self.item_type, self.item_id) end end diff --git a/app/views/report/index.html.haml b/app/views/report/index.html.haml index b27826a28..a45b048ca 100644 --- a/app/views/report/index.html.haml +++ b/app/views/report/index.html.haml @@ -6,16 +6,17 @@ = t('report.title') %div#reports - @reports.each do |r| + - username = User.find_by_id(r.user_id).username %div.content %span - = report_content(r.post_id, r.post_type) + = report_content(r.item_id, r.item_type) %span - = raw t('report.reported_label', person: link_to(r.user_id, user_profile_path(r.user_id))) + = raw t('report.reported_label', person: link_to(username, user_profile_path(username))) %span = t('report.reason_label', text: r.text) %div.options %span - = link_to t('report.review_link'), report_path(r.id, :type => r.post_type), method: :put + = link_to t('report.review_link'), report_path(r.id, :type => r.item_type), method: :put %span - = link_to t('report.delete_link'), report_path(r.id, :type => r.post_type), method: :delete + = link_to t('report.delete_link'), report_path(r.id, :type => r.item_type), method: :delete %div.clear diff --git a/db/migrate/20140422134050_rename_post_columns_to_item.rb b/db/migrate/20140422134050_rename_post_columns_to_item.rb new file mode 100644 index 000000000..4550eacd7 --- /dev/null +++ b/db/migrate/20140422134050_rename_post_columns_to_item.rb @@ -0,0 +1,11 @@ +class RenamePostColumnsToItem < ActiveRecord::Migration + def up + rename_column :reports, :post_id, :item_id + rename_column :reports, :post_type, :item_type + end + + def down + rename_column :reports, :item_id, :post_id + rename_column :reports, :item_type, :post_type + end +end diff --git a/db/migrate/20140422134627_change_user_id_type_to_integer.rb b/db/migrate/20140422134627_change_user_id_type_to_integer.rb new file mode 100644 index 000000000..de21f2bd3 --- /dev/null +++ b/db/migrate/20140422134627_change_user_id_type_to_integer.rb @@ -0,0 +1,9 @@ +class ChangeUserIdTypeToInteger < ActiveRecord::Migration + def up + change_column :reports, :user_id, :integer + end + + def down + change_column :reports, :user_id, :string + end +end diff --git a/db/migrate/20140422135040_drop_table_post_reports.rb b/db/migrate/20140422135040_drop_table_post_reports.rb new file mode 100644 index 000000000..1d7ba7e15 --- /dev/null +++ b/db/migrate/20140422135040_drop_table_post_reports.rb @@ -0,0 +1,9 @@ +class DropTablePostReports < ActiveRecord::Migration + def up + drop_table :post_reports + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index b483d9b03..2d633c2a6 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 => 20140308154022) do +ActiveRecord::Schema.define(:version => 20140422135040) do create_table "account_deletions", :force => true do |t| t.string "diaspora_handle" @@ -316,17 +316,6 @@ ActiveRecord::Schema.define(:version => 20140308154022) do add_index "polls", ["status_message_id"], :name => "index_polls_on_status_message_id" - create_table "post_reports", :force => true do |t| - t.integer "post_id", :null => false - t.string "user_id" - t.boolean "reviewed", :default => false - t.text "text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - add_index "post_reports", ["post_id"], :name => "index_post_reports_on_post_id" - create_table "posts", :force => true do |t| t.integer "author_id", :null => false t.boolean "public", :default => false, :null => false @@ -411,16 +400,16 @@ ActiveRecord::Schema.define(:version => 20140308154022) do add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories" create_table "reports", :force => true do |t| - t.integer "post_id", :null => false - t.string "post_type", :null => false - t.string "user_id" + t.integer "item_id", :null => false + t.string "item_type", :null => false + t.integer "user_id" t.boolean "reviewed", :default => false t.text "text" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end - add_index "reports", ["post_id"], :name => "index_post_reports_on_post_id" + add_index "reports", ["item_id"], :name => "index_post_reports_on_post_id" create_table "roles", :force => true do |t| t.integer "person_id" diff --git a/spec/controllers/report_controller_spec.rb b/spec/controllers/report_controller_spec.rb index 719ee2bbb..9c48503c0 100644 --- a/spec/controllers/report_controller_spec.rb +++ b/spec/controllers/report_controller_spec.rb @@ -33,21 +33,21 @@ describe ReportController do describe '#create' do let(:comment_hash) { {:text =>"facebook, is that you?", - :post_id =>"#{@post.id}"} + :item_id =>"#{@post.id}"} } context 'report offensive post' do it 'succeeds' do - put :create, :report => { :post_id => @message.id, :post_type => 'post', :text => 'offensive content' } + put :create, :report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' } response.status.should == 200 - Report.exists?(:post_id => @message.id, :post_type => 'post').should be_true + Report.exists?(:item_id => @message.id, :item_type => 'post').should be_true end end context 'report offensive comment' do it 'succeeds' do - put :create, :report => { :post_id => @comment.id, :post_type => 'comment', :text => 'offensive content' } + put :create, :report => { :item_id => @comment.id, :item_type => 'comment', :text => 'offensive content' } response.status.should == 200 - Report.exists?(:post_id => @comment.id, :post_type => 'comment').should be_true + Report.exists?(:item_id => @comment.id, :item_type => 'comment').should be_true end end end @@ -57,14 +57,14 @@ describe ReportController do it 'is behind redirect_unless_admin' do put :update, :id => @message.id, :type => 'post' response.should redirect_to stream_path - Report.where(:reviewed => false, :post_id => @message.id, :post_type => 'post').should be_true + Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_true end end context 'mark comment report as user' do it 'is behind redirect_unless_admin' do put :update, :id => @comment.id, :type => 'comment' response.should redirect_to stream_path - Report.where(:reviewed => false, :post_id => @comment.id, :post_type => 'comment').should be_true + Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_true end end @@ -75,7 +75,7 @@ describe ReportController do it 'succeeds' do put :update, :id => @message.id, :type => 'post' response.status.should == 302 - Report.where(:reviewed => true, :post_id => @message.id, :post_type => 'post').should be_true + Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_true end end context 'mark comment report as admin' do @@ -85,7 +85,7 @@ describe ReportController do it 'succeeds' do put :update, :id => @comment.id, :type => 'comment' response.status.should == 302 - Report.where(:reviewed => true, :post_id => @comment.id, :post_type => 'comment').should be_true + Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_true end end end @@ -95,14 +95,14 @@ describe ReportController do it 'is behind redirect_unless_admin' do delete :destroy, :id => @message.id, :type => 'post' response.should redirect_to stream_path - Report.where(:reviewed => false, :post_id => @message.id, :post_type => 'post').should be_true + Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_true end end context 'destroy comment as user' do it 'is behind redirect_unless_admin' do delete :destroy, :id => @comment.id, :type => 'comment' response.should redirect_to stream_path - Report.where(:reviewed => false, :post_id => @comment.id, :post_type => 'comment').should be_true + Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_true end end @@ -113,7 +113,7 @@ describe ReportController do it 'succeeds' do delete :destroy, :id => @message.id, :type => 'post' response.status.should == 302 - Report.where(:reviewed => true, :post_id => @message.id, :post_type => 'post').should be_true + Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_true end end context 'destroy comment as admin' do @@ -123,7 +123,7 @@ describe ReportController do it 'succeeds' do delete :destroy, :id => @comment.id, :type => 'comment' response.status.should == 302 - Report.where(:reviewed => true, :post_id => @comment.id, :post_type => 'comment').should be_true + Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_true end end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 387a77f89..82d5d8603 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -6,30 +6,30 @@ require 'spec_helper' describe Report do before do - #:report => { :post_id => @message.id, :post_type => 'post', :text => 'offensive content' } + #:report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' } @user = bob @bob_post = @user.post(:status_message, :text => "hello", :to => @user.aspects.first.id) @bob_comment = @user.comment!(@bob_post, "welcome") @valid_post_report = { - :post_id => @bob_post.id, - :post_type => 'post', + :item_id => @bob_post.id, + :item_type => 'post', :text => 'offensive content' } @valid_comment_report = { - :post_id => @bob_comment.id, - :post_type => 'comment', + :item_id => @bob_comment.id, + :item_type => 'comment', :text => 'offensive content' } end describe '#validation' do it 'validates that post ID is required' do - @user.reports.build(:post_type => 'post', :text => 'blub').should_not be_valid + @user.reports.build(:item_type => 'post', :text => 'blub').should_not be_valid end it 'validates that post type is required' do - @user.reports.build(:post_id => 666, :text => 'blub').should_not be_valid + @user.reports.build(:item_id => 666, :text => 'blub').should_not be_valid end it 'validates that entry does not exist' do |