Skip to content

Instantly share code, notes, and snippets.

@osiro
Last active December 11, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osiro/4671123 to your computer and use it in GitHub Desktop.
Save osiro/4671123 to your computer and use it in GitHub Desktop.
###### MODEL
class JukeboxRoom < ActiveRecord::Base
#..code here
scope :expired, where{ expires_at <= Time.now }
#..code here
end
###### SPEC
require 'spec_helper'
describe JukeboxRoom do
describe "#expired" do
subject { JukeboxRoom.expired }
before(:all) do
Timecop.freeze(Time.now)
JukeboxRoom.skip_callback(:create, :before, :set_expire_date)
end
after(:all) { Timecop.return }
let(:open_jukebox_room) { FactoryGirl.create :jukebox_room, expires_at: 24.hours.from_now }
let(:expired_jukebox_room) { FactoryGirl.create :jukebox_room, expires_at: 1.second.ago }
# This fuckin test doesnt pass
it 'should include expired jukebox rooms' do
debugger
should include expired_jukebox_room
end
end
end
###### CONSOLE
# When debugging..
JukeboxRoom.expired
[]
# Exactly what my scope does
JukeboxRoom.where{ expires_at <= Time.now }
[<JukeboxRoom id: 1, owner_id: 1, expires_at: "2013-01-30 06:06:58", vote_only: false, playlist_id: nil, code: "85755", code_required: false, created_at: "2013-01-30 06:06:59", updated_at: "2013-01-30 06:06:59">]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment