-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add time-based slides #34
Open
kevinnio
wants to merge
11
commits into
spree-contrib:master
Choose a base branch
from
magma-labs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
de67be3
add migration for new starts_at and ends_at columns
kevinnio 78d5461
add fields for starts_at and ends_at in slider admin
kevinnio 69c3c1e
add scope to load all in time slides from database
kevinnio 4ced35b
refactor new methods in Slide model
kevinnio e4d3d71
change Time.now for Time.current
kevinnio 5ee54ee
rename spec file for Slide model
kevinnio 1272cb1
add migration to add location fallback column
kevinnio e48ffef
edit fallback slide for each location in admin
kevinnio ff150e2
exclude fallback slide from location slides
kevinnio cc78a0d
order fallback slides by name
kevinnio fcd9e2b
create dummy app for testing in Travis environment
kevinnio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
db/migrate/20170906023647_add_starts_at_and_ends_at_columns_to_spree_slides.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddStartsAtAndEndsAtColumnsToSpreeSlides < ActiveRecord::Migration | ||
def change | ||
add_column :spree_slides, :starts_at, :datetime | ||
add_column :spree_slides, :ends_at, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Spree::Slide do | ||
describe '#in_time?' do | ||
context 'when both starts_at and ends_at are nil' do | ||
subject { Spree::Slide.new starts_at: nil, ends_at: nil } | ||
|
||
it { is_expected.to be_in_time } | ||
end | ||
|
||
context 'when starts_at is in the past and ends_at is nil' do | ||
subject { Spree::Slide.new starts_at: 2.days.ago, ends_at: nil } | ||
|
||
it { is_expected.to be_in_time } | ||
end | ||
|
||
context 'when starts_at is in the future and ends_at is nil' do | ||
subject { Spree::Slide.new starts_at: 2.days.from_now, ends_at: nil } | ||
|
||
it { is_expected.not_to be_in_time } | ||
end | ||
|
||
context 'when starts_at is nil and ends_at is in the future' do | ||
subject { Spree::Slide.new starts_at: nil, ends_at: 2.days.from_now } | ||
|
||
it { is_expected.to be_in_time } | ||
end | ||
|
||
context 'when starts_at is nil and ends_at is in the past' do | ||
subject { Spree::Slide.new starts_at: nil, ends_at: 2.days.ago } | ||
|
||
it { is_expected.not_to be_in_time } | ||
end | ||
|
||
context 'when both starts_at and end_at is in the past' do | ||
subject { Spree::Slide.new starts_at: 2.days.ago, ends_at: 1.day.ago } | ||
|
||
it { is_expected.not_to be_in_time } | ||
end | ||
|
||
context 'when starts_at is in the past and end_at is in the future' do | ||
subject { Spree::Slide.new starts_at: 2.days.ago, ends_at: 2.days.from_now } | ||
|
||
it { is_expected.to be_in_time } | ||
end | ||
end | ||
|
||
describe '.in_time' do | ||
it 'returns all the slides from the database that are in time' do | ||
good_slides = [ | ||
Spree::Slide.create(starts_at: nil, ends_at: nil), | ||
Spree::Slide.create(starts_at: 2.days.ago, ends_at: nil), | ||
Spree::Slide.create(starts_at: nil, ends_at: 2.days.from_now), | ||
Spree::Slide.create(starts_at: 2.days.ago, ends_at: 2.days.from_now) | ||
].map(&:id) | ||
|
||
bad_slides = [ | ||
Spree::Slide.create(starts_at: 2.days.from_now, ends_at: nil), | ||
Spree::Slide.create(starts_at: nil, ends_at: 2.days.ago), | ||
Spree::Slide.create(starts_at: 2.days.ago, ends_at: 1.day.ago) | ||
].map(&:id) | ||
|
||
slides = Spree::Slide.in_time.map(&:id) | ||
expect(slides).to include *good_slides | ||
expect(slides).not_to include *bad_slides | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Favor the use of
Time.current
instead ofTime.now
Source