aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/user_spec.rb
blob: e22e5379709dc34f344b64b9baec999f07556f5a (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){create(:organisation)}
    let!(:user){create(:user, :organisation => organisation)}
    context "user's organisation contains many user" do
      let!(:other_user){create(: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