BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
df496fca
Commit
df496fca
authored
Dec 31, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update BroadcastMessage model
- Adds default values for `color` and `font` attributes - Adds `active?`, `started?`, `ended?`, and 'status' methods
parent
5a170679
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
6 deletions
+117
-6
broadcast_message.rb
app/models/broadcast_message.rb
+26
-1
broadcast_messages.rb
spec/factories/broadcast_messages.rb
+5
-0
broadcast_message_spec.rb
spec/models/broadcast_message_spec.rb
+86
-5
No files found.
app/models/broadcast_message.rb
View file @
df496fca
...
...
@@ -22,7 +22,32 @@ class BroadcastMessage < ActiveRecord::Base
validates
:color
,
allow_blank:
true
,
color:
true
validates
:font
,
allow_blank:
true
,
color:
true
default_value_for
:color
,
'#E75E40'
default_value_for
:font
,
'#FFFFFF'
def
self
.
current
where
(
"ends_at > :now AND starts_at < :now"
,
now:
Time
.
zone
.
now
).
last
where
(
"ends_at > :now AND starts_at <= :now"
,
now:
Time
.
zone
.
now
).
last
end
def
active?
started?
&&
!
ended?
end
def
started?
Time
.
zone
.
now
>=
starts_at
end
def
ended?
ends_at
<
Time
.
zone
.
now
end
def
status
if
active?
'Active'
elsif
ended?
'Expired'
else
'Pending'
end
end
end
spec/factories/broadcast_messages.rb
View file @
df496fca
...
...
@@ -24,5 +24,10 @@ FactoryGirl.define do
starts_at
5
.
days
.
ago
ends_at
3
.
days
.
ago
end
trait
:future
do
starts_at
5
.
days
.
from_now
ends_at
6
.
days
.
from_now
end
end
end
spec/models/broadcast_message_spec.rb
View file @
df496fca
...
...
@@ -15,6 +15,8 @@
require
'spec_helper'
describe
BroadcastMessage
,
models:
true
do
include
ActiveSupport
::
Testing
::
TimeHelpers
subject
{
create
(
:broadcast_message
)
}
it
{
is_expected
.
to
be_valid
}
...
...
@@ -34,20 +36,99 @@ describe BroadcastMessage, models: true do
it
{
is_expected
.
not_to
allow_value
(
'000'
).
for
(
:font
)
}
end
describe
:current
do
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
)
expect
(
BroadcastMessage
.
current
).
to
eq
(
broadcast_message
)
message
=
create
(
:broadcast_message
)
expect
(
BroadcastMessage
.
current
).
to
eq
message
end
it
"should return nil if time not come"
do
create
(
:broadcast_message
,
starts_at:
Time
.
now
.
tomorrow
,
ends_at:
Time
.
now
+
2
.
days
)
create
(
:broadcast_message
,
:future
)
expect
(
BroadcastMessage
.
current
).
to
be_nil
end
it
"should return nil if time has passed"
do
create
(
:broadcast_message
,
starts_at:
Time
.
now
-
2
.
days
,
ends_at:
Time
.
now
.
yesterday
)
create
(
:broadcast_message
,
:expired
)
expect
(
BroadcastMessage
.
current
).
to
be_nil
end
end
describe
'#active?'
do
it
'is truthy when started and not ended'
do
message
=
build
(
:broadcast_message
)
expect
(
message
).
to
be_active
end
it
'is falsey when ended'
do
message
=
build
(
:broadcast_message
,
:expired
)
expect
(
message
).
not_to
be_active
end
it
'is falsey when not started'
do
message
=
build
(
:broadcast_message
,
:future
)
expect
(
message
).
not_to
be_active
end
end
describe
'#started?'
do
it
'is truthy when starts_at has passed'
do
message
=
build
(
:broadcast_message
)
travel_to
(
3
.
days
.
from_now
)
do
expect
(
message
).
to
be_started
end
end
it
'is falsey when starts_at is in the future'
do
message
=
build
(
:broadcast_message
)
travel_to
(
3
.
days
.
ago
)
do
expect
(
message
).
not_to
be_started
end
end
end
describe
'#ended?'
do
it
'is truthy when ends_at has passed'
do
message
=
build
(
:broadcast_message
)
travel_to
(
3
.
days
.
from_now
)
do
expect
(
message
).
to
be_ended
end
end
it
'is falsey when ends_at is in the future'
do
message
=
build
(
:broadcast_message
)
travel_to
(
3
.
days
.
ago
)
do
expect
(
message
).
not_to
be_ended
end
end
end
describe
'#status'
do
it
'returns Active'
do
message
=
build
(
:broadcast_message
)
expect
(
message
.
status
).
to
eq
'Active'
end
it
'returns Expired'
do
message
=
build
(
:broadcast_message
,
:expired
)
expect
(
message
.
status
).
to
eq
'Expired'
end
it
'returns Pending'
do
message
=
build
(
:broadcast_message
,
:future
)
expect
(
message
.
status
).
to
eq
'Pending'
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment