dchelimsky (owner)

Fork Of

gist: 213636 by iain Weird RSpec issue

Revisions

gist: 215201 Download_button fork
public
Public Clone URL: git://gist.github.com/215201.git
Embed All Files: show embed
user.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean
# created_at :datetime
# updated_at :datetime
#
 
class User < ActiveRecord::Base
  named_scope :active, :conditions => { :active => true }
end
user_spec.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
describe User do
 
  it "should get all active users" do
    active = User.create!(:active => true)
    inactive = User.create!(:active => false)
 
    subject = User.active
    subject.should be_all(&:active)
 
    inverse = User.all - subject
 
    inverse.none?(&:active).should be_true
    inverse.any?(&:active).should be_false
 
    # inverse.should be_none(&:active)
    inverse.should_not be_any(&:active)
  end
 
end