Merge branch 'bugfix/284_sticky_does_not_apply_to_forum' into dev

pull/1043/head
Hagen Schink 11 years ago
commit 05b47774de
  1. 6
      app/controllers/boards_controller.rb
  2. 4
      app/models/board.rb
  3. 10
      app/models/message.rb
  4. 34
      db/migrate/20140311120609_add_sticked_on_field_to_messages.rb
  5. 17
      features/messages/message.feature
  6. 3
      features/step_definitions/common_steps.rb
  7. 59
      spec/controllers/boards_controller_spec.rb

@ -58,16 +58,18 @@ class BoardsController < ApplicationController
'replies' => "#{Message.table_name}.replies_count",
'updated_on' => "#{Message.table_name}.updated_on"
@topics = @board.topics.order(["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '))
@topics = @board.topics.order(["#{Message.table_name}.sticked_on ASC", sort_clause].compact.join(', '))
.includes(:author, { :last_reply => :author })
.page(params[:page])
.per_page(per_page_param)
@message = Message.new
render :action => 'show', :layout => !request.xhr?
}
format.atom {
@messages = @board.messages.order('created_on DESC')
@messages = @board.messages.order(["#{Message.table_name}.sticked_on ASC", sort_clause].compact.join(', '))
.includes(:author, :board)
.limit(Setting.feeds_limit.to_i)

@ -31,8 +31,8 @@ class Board < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
belongs_to :project
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL" , :order => "#{Message.table_name}.sticky DESC"
has_many :messages, :dependent => :destroy , :order => "#{Message.table_name}.sticky DESC"
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id
acts_as_list :scope => :project_id
acts_as_watchable

@ -85,11 +85,21 @@ class Message < ActiveRecord::Base
validate :validate_unlocked_root, :on => :create
before_save :set_sticked_on_date
# Can not reply to a locked topic
def validate_unlocked_root
errors.add :base, 'Topic is locked' if root.locked? && self != root
end
def set_sticked_on_date
if sticky?
self.sticked_on = sticked_on.nil? ? Time.now : sticked_on
else
self.sticked_on = nil
end
end
def update_last_reply_in_parent
if parent
parent.reload.update_attribute(:last_reply_id, self.id)

@ -0,0 +1,34 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
class AddStickedOnFieldToMessages < ActiveRecord::Migration
def change
add_column :messages, :sticked_on, :datetime, default: nil, null: true
end
end

@ -27,6 +27,7 @@
#++
Feature: Issue textile quickinfo links
Background:
Given there is 1 project with the following:
| name | parent |
@ -43,7 +44,7 @@ Feature: Issue textile quickinfo links
| delete_messages |
| delete_own_messages |
And there is 1 user with the following:
| login | bob|
| login | bob |
And the user "bob" is a "member" in the project "parent"
And I am already logged in as "bob"
@ -86,3 +87,17 @@ Feature: Issue textile quickinfo links
When I click on the first button matching "Create"
Then there should be an error message
Then the "message_content" field should contain "Here you find the most frequently asked questions"
Scenario: Sticky message on top of messages list
Given the board "development discussion" has the following messages:
| message #1 |
| message #2 |
| message #3 |
When I go to the boards page of the project called "parent"
And I follow "New message"
And I fill in "How to?" for "message_subject"
And I fill in "How to st-up project on local mashine." for "message_content"
And I check "Sticky"
When I click on the first button matching "Create"
And I go to the boards page of the project called "parent"
Then "How to?" should be the first row in table

@ -75,3 +75,6 @@ Then(/^I should see the following fields:$/) do |table|
end
end
Then(/^"([^"]*)" should be the first row in table$/) do |name|
should have_selector("table.list tbody tr td", :text => Regexp.new("#{name}"))
end

@ -175,4 +175,63 @@ describe BoardsController do
end
end
describe :sticky do
let!(:message1) { FactoryGirl.create(:message, board: board) }
let!(:message2) { FactoryGirl.create(:message, board: board) }
let!(:sticked_message1) { FactoryGirl.create(:message, board_id: board.id, subject: "How to",
content: "How to install this cool app", sticky: "1", sticked_on: Time.now - 2.minute) }
let!(:sticked_message2) { FactoryGirl.create(:message, board_id: board.id, subject: "FAQ",
content: "Frequestly asked question", sticky: "1", sticked_on: Time.now - 1.minute) }
describe "all sticky messages" do
before do
@controller.should_receive(:authorize)
get :show, project_id: project.id, id: board.id
end
it { expect(response).to render_template 'show' }
it "should be displayed on top" do
expect(assigns[:topics][0].id).to eq(sticked_message1.id)
end
end
describe "edit a sticky message" do
before(:each) do
sticked_message1.sticky = 0
sticked_message1.save!
end
describe "when sticky is unset from message" do
before do
@controller.should_receive(:authorize)
get :show, project_id: project.id, id: board.id
end
it "it should not be displayed as sticky message" do
expect(sticked_message1.sticked_on).to be_nil
expect(assigns[:topics][0].id).to_not eq(sticked_message1.id)
end
end
describe "when sticky is set back to message" do
before do
sticked_message1.sticky = 1
sticked_message1.save!
@controller.should_receive(:authorize)
get :show, project_id: project.id, id: board.id
end
it "it should not be displayed on first position" do
expect(assigns[:topics][0].id).to eq(sticked_message2.id)
end
end
end
end
end

Loading…
Cancel
Save