Commit c5b667351abcda4b5ac134873007a0ce47976e88
1 parent
963a3114
Exists in
master
and in
4 other branches
Show broadcast message to users
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
7 changed files
with
38 additions
and
0 deletions
Show diff stats
app/assets/stylesheets/common.scss
app/helpers/application_helper.rb
app/models/broadcast_message.rb
| ... | ... | @@ -4,4 +4,8 @@ class BroadcastMessage < ActiveRecord::Base |
| 4 | 4 | validates :message, presence: true |
| 5 | 5 | validates :starts_at, presence: true |
| 6 | 6 | validates :ends_at, presence: true |
| 7 | + | |
| 8 | + def self.current | |
| 9 | + where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last | |
| 10 | + end | |
| 7 | 11 | end | ... | ... |
app/views/layouts/application.html.haml
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | %html{ lang: "en"} |
| 3 | 3 | = render "layouts/head", title: "Dashboard" |
| 4 | 4 | %body{class: "#{app_theme} application", :'data-page' => body_data_page } |
| 5 | + = render "layouts/broadcast" | |
| 5 | 6 | = render "layouts/head_panel", title: "Dashboard" |
| 6 | 7 | = render "layouts/flash" |
| 7 | 8 | %nav.main-nav | ... | ... |
app/views/layouts/projects.html.haml
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | %html{ lang: "en"} |
| 3 | 3 | = render "layouts/head", title: @project.name_with_namespace |
| 4 | 4 | %body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id } |
| 5 | + = render "layouts/broadcast" | |
| 5 | 6 | = render "layouts/head_panel", title: project_title(@project) |
| 6 | 7 | = render "layouts/init_auto_complete" |
| 7 | 8 | = render "layouts/flash" | ... | ... |
spec/models/broadcast_message_spec.rb
| ... | ... | @@ -4,4 +4,21 @@ describe BroadcastMessage do |
| 4 | 4 | subject { create(:broadcast_message) } |
| 5 | 5 | |
| 6 | 6 | it { should be_valid } |
| 7 | + | |
| 8 | + describe :current do | |
| 9 | + it "should return last message if time match" do | |
| 10 | + broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow) | |
| 11 | + BroadcastMessage.current.should == broadcast_message | |
| 12 | + end | |
| 13 | + | |
| 14 | + it "should return nil if time not come" do | |
| 15 | + broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) | |
| 16 | + BroadcastMessage.current.should be_nil | |
| 17 | + end | |
| 18 | + | |
| 19 | + it "should return nil if time has passed" do | |
| 20 | + broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) | |
| 21 | + BroadcastMessage.current.should be_nil | |
| 22 | + end | |
| 23 | + end | |
| 7 | 24 | end | ... | ... |