aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/user_spec.rb
blob: c818f9673d79bdc5852c67f662e6c8bbfd8eba4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'spec_helper'

describe User, :type => :model do
  #it { should validate_uniqueness_of :email }
  #it { should validate_presence_of :name }

  describe "#destroy" do
    let!(:organisation){Factory(:organisation)}
    let!(:user){Factory(:user, :organisation => organisation)}
    context "user's organisation contains many user" do
      let!(:other_user){Factory(:user, :organisation => organisation)}
      it "should destoy also user's organisation" do
        user.destroy
        expect(Organisation.where(:name => organisation.name).exists?).to be_truthy
        read_organisation = Organisation.where(:name => organisation.name).first
        expect(read_organisation.users.count).to eq(1)
        expect(read_organisation.users.first).to eq(other_user)
      end
    end
  end
end