Commit c5b66735 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Show broadcast message to users

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 963a3114
......@@ -351,3 +351,10 @@ table {
@extend .btn-new;
padding: 5px 15px;
}
.broadcast-message {
padding: 10px;
text-align: center;
background: #555;
color: #BBB;
}
......@@ -208,4 +208,8 @@ module ApplicationHelper
line += "..." if lines.size > 1
line
end
def broadcast_message
BroadcastMessage.current
end
end
......@@ -4,4 +4,8 @@ class BroadcastMessage < ActiveRecord::Base
validates :message, presence: true
validates :starts_at, presence: true
validates :ends_at, presence: true
def self.current
where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last
end
end
- if broadcast_message.present?
.broadcast-message
%i.icon-bullhorn
= broadcast_message.message
......@@ -2,6 +2,7 @@
%html{ lang: "en"}
= render "layouts/head", title: "Dashboard"
%body{class: "#{app_theme} application", :'data-page' => body_data_page }
= render "layouts/broadcast"
= render "layouts/head_panel", title: "Dashboard"
= render "layouts/flash"
%nav.main-nav
......
......@@ -2,6 +2,7 @@
%html{ lang: "en"}
= render "layouts/head", title: @project.name_with_namespace
%body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id }
= render "layouts/broadcast"
= render "layouts/head_panel", title: project_title(@project)
= render "layouts/init_auto_complete"
= render "layouts/flash"
......
......@@ -4,4 +4,21 @@ describe BroadcastMessage do
subject { create(:broadcast_message) }
it { should be_valid }
describe :current do
it "should return last message if time match" do
broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow)
BroadcastMessage.current.should == broadcast_message
end
it "should return nil if time not come" do
broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
BroadcastMessage.current.should be_nil
end
it "should return nil if time has passed" do
broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
BroadcastMessage.current.should be_nil
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment