aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorMarc Florisson2012-08-24 11:46:09 +0200
committerMarc Florisson2012-08-24 11:46:09 +0200
commit6fd69ca92e3090a2a8b7b73e7511bc1070290e22 (patch)
tree8f25b31f44fe9b239b25d232f8aee8844c7d0688 /spec
parent1fd4e99d38e25ba4e70324a2f06aa532ee0e7862 (diff)
downloadchouette-core-6fd69ca92e3090a2a8b7b73e7511bc1070290e22.tar.bz2
create organisation
Diffstat (limited to 'spec')
-rw-r--r--spec/factories.rb5
-rw-r--r--spec/mailers/user_mailer_spec.rb21
-rw-r--r--spec/models/user_spec.rb18
3 files changed, 43 insertions, 1 deletions
diff --git a/spec/factories.rb b/spec/factories.rb
index 8e62b3b64..c530ea650 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -8,7 +8,12 @@ FactoryGirl.define do
f.time_zone "Europe/Paris"
end
+ factory :organisation do |f|
+ f.sequence(:name) { |n| "Organisation #{n}" }
+ end
+
factory :user do |f|
+ f.association :organisation
f.sequence(:email) { |n| "chouette#{n}@dryade.priv" }
f.password "secret"
f.password_confirmation "secret"
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb
new file mode 100644
index 000000000..2471de988
--- /dev/null
+++ b/spec/mailers/user_mailer_spec.rb
@@ -0,0 +1,21 @@
+require "spec_helper"
+
+describe UserMailer do
+
+ describe "welcome" do
+ let(:user) {Factory(:user)}
+
+ it "should verify if email send" do
+ email = UserMailer.welcome(user).deliver
+ ActionMailer::Base.deliveries.empty?.should be_false
+ end
+
+ it "should verify the content of sending email" do
+ email = UserMailer.welcome(user).deliver
+ email.to.should == [user.email]
+ email.subject.should == "Welcome to #{user.organisation.name}"
+ end
+
+ end
+
+end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 44032b484..dbf95a120 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -1,5 +1,21 @@
require 'spec_helper'
describe User do
- pending "add some examples to (or delete) #{__FILE__}"
+ #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
+ Organisation.where(:name => organisation.name).exists?.should be_true
+ read_organisation = Organisation.where(:name => organisation.name).first
+ read_organisation.users.count.should == 1
+ read_organisation.users.first.should == other_user
+ end
+ end
+ end
end