Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  app/models/message_thread.rb
@@ -132,7 +132,7 @@ def latest_activity_at
end
def upcoming_deadline_messages
- messages.joins("JOIN deadline_messages dm ON messages.component_id = dm.id").
+ messages.except(:order).joins("JOIN deadline_messages dm ON messages.component_id = dm.id").
where("messages.component_type = 'DeadlineMessage'").
where("dm.deadline > now()").
order("dm.deadline ASC")
View
13 spec/factories/messages/deadline_message.rb
@@ -0,0 +1,13 @@
+FactoryGirl.define do
+ factory :deadline_message do
+ association :created_by, factory: :user
+ association :message, factory: :message
+ sequence(:title) {|n| "Imaginative deadline title #{n}" }
+ sequence(:deadline) { |n| Time.now + n.days }
+
+ after_build do |o|
+ o.thread = o.message.thread
+ o.message.update_attributes(component: o)
+ end
+ end
+end
View
27 spec/models/message_thread_spec.rb
@@ -97,6 +97,33 @@
end
end
+ describe "upcoming deadlines" do
+ let(:thread) { FactoryGirl.create(:message_thread) }
+ let(:deadline_message_old) { FactoryGirl.create(:deadline_message, message: FactoryGirl.create(:message, thread: thread), deadline: Time.now - 10.days)}
+ let(:deadline_message_soon) { FactoryGirl.create(:deadline_message, message: FactoryGirl.create(:message, thread: thread), deadline: Time.now + 2.days)}
+ let(:deadline_message_later) { FactoryGirl.create(:deadline_message, message: FactoryGirl.create(:message, thread: thread), deadline: Time.now + 100.days)}
+
+ it "should return one thread with upcoming deadlines" do
+ deadline_message_soon
+ deadline_message_later
+ MessageThread.with_upcoming_deadlines.count.should == 1
+ end
+
+ it "should ingnore threads with old deadlines" do
+ deadline_message_old
+ MessageThread.with_upcoming_deadlines.count.should == 0
+ end
+
+ it "should return deadline messages in order" do
+ deadline_message_old
+ deadline_message_later
+ deadline_message_soon
+ messages = thread.upcoming_deadline_messages
+ messages.count.should == 2
+ messages.first.should == deadline_message_soon.message
+ end
+ end
+
describe ".order_by_latest_message" do
it "should return threads with most recent messages first" do
threads = FactoryGirl.create_list(:message_thread, 3, :with_messages)
View
22 spec/requests/dashboards_spec.rb
@@ -104,5 +104,27 @@
end
end
end
+
+ context "deadlines" do
+ include_context "signed in as a site user"
+
+ context "no deadlines" do
+ it "should give a warning" do
+ visit dashboard_path
+ page.should have_content(I18n.t(".dashboards.show.no_upcoming_deadline_threads"))
+ end
+ end
+
+ context "with a deadline" do
+ let!(:message) { FactoryGirl.create(:message, created_by: current_user) }
+ let!(:deadline) { FactoryGirl.create(:deadline_message, message: FactoryGirl.create(:message, thread: message.thread)) }
+
+ it "should show the deadline" do
+ visit dashboard_path
+ page.should have_content(deadline.title)
+ page.should have_content(I18n.l(deadline.deadline.to_date, format: :long))
+ end
+ end
+ end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.