Sha256: 2c1a5e3c57cf74dc4eab9fc20e7981f921120b38cf7fcbafb753c65f5475d7fe

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe Account do
  subject { Factory(:account) }

  it { should have_many(:memberships) }
  it { should have_many(:users).through(:memberships) }
  it { should have_many(:projects) }

  it { should validate_uniqueness_of(:name) }
  it { should validate_uniqueness_of(:keyword) }
  it { should validate_presence_of(  :name) }
  it { should validate_presence_of(:keyword) }

  it { should_not allow_mass_assignment_of(:id) }
  it { should_not allow_mass_assignment_of(:updated_at) }
  it { should_not allow_mass_assignment_of(:created_at) }
  it { should allow_mass_assignment_of(:keyword) }

  [nil, "", "a b", "a.b", "a%b"].each do |value|
    it { should_not allow_value(value).for(:keyword).with_message(/letters/i) }
  end

  ["foo", "f00", "37signals"].each do |value|
    it { should allow_value(value).for(:keyword) }
  end

  it "should give its keyword for to_param" do
    subject.to_param.should == subject.keyword
  end

  it "finds admin users" do
    admins = [Factory(:user), Factory(:user)]
    non_admin = Factory(:user)
    non_member = Factory(:user)
    admins.each do |admin|
      Factory(:membership, :user => admin, :account => subject, :admin => true)
    end
    Factory(:membership, :user => non_admin, :account => subject, :admin => false)

    result = subject.admins

    result.to_a.should =~ admins
  end

  it "has a member with a membership" do
    membership = Factory(:membership, :account => subject)
    should have_member(membership.user)
  end

  it "doesn't have a member without a membership" do
    membership = Factory(:membership, :account => subject)
    should_not have_member(Factory(:user))
  end

  it "finds memberships by name" do
    expected = 'expected result'
    memberships = stub('memberships', :by_name => expected)
    account = Factory.stub(:account)
    account.stubs(:memberships => memberships)

    result = account.memberships_by_name

    result.should == expected
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
saucy-0.1.18 spec/models/account_spec.rb
saucy-0.1.17 spec/models/account_spec.rb
saucy-0.1.16 spec/models/account_spec.rb
saucy-0.1.15 spec/models/account_spec.rb
saucy-0.1.14 spec/models/account_spec.rb
saucy-0.1.13 spec/models/account_spec.rb
saucy-0.1.12 spec/models/account_spec.rb