diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 54e647f..7f8e93d 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -33,6 +33,8 @@ class TeamsController < ApplicationController unless person.teams.include? team unless person == current_person Membership.create_pending_membership current_person, team, person + organisation = person.organisation + team.add_to organisation end end redirect_to "/teams/#{team.slug}" diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 46eff25..83a894e 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe TeamsController do render_views - + before(:each) do @person = sign_in @organisation = Organisation.create(name: 'ThoughtWorks', domains: 'thoughtworks.com') @@ -30,15 +30,15 @@ describe TeamsController do team = @person.teams.create(name: 'LSP', slug: 'lsp') get :show, :slug => team.slug response.should be_success - assert_select '#join-team',{:value=> 'Join Team'} + assert_select '#join-team', {:value => 'Join Team'} end it 'ensure a button display with quit team if we already joined this team' do - team = @person.teams.create(name: 'LSP', slug: 'lsp') - get :show ,:slug => team.slug - response.should be_success + team = @person.teams.create(name: 'LSP', slug: 'lsp') + get :show, :slug => team.slug + response.should be_success - assert_select '#join-team',{:value=> 'Quit Team'} + assert_select '#join-team', {:value => 'Quit Team'} end end @@ -67,10 +67,10 @@ describe TeamsController do it 'ensure when person quit from a team then join it again,and it will not disappear in past situation' do team = @person.teams.create(name: 'LSP', slug: 'lsp') - post :join ,:slug =>team.slug - post :quit, :slug => team.slug - post :join ,:slug =>team.slug - membership = Membership.find(:last).ended.should == nil + post :join, :slug => team.slug + post :quit, :slug => team.slug + post :join, :slug => team.slug + membership = Membership.find(:last).ended.should == nil end it 'ensure person can not join a team that he is not belong to the organisation of that team' do @@ -86,10 +86,25 @@ describe TeamsController do post :join, :slug => team.slug lambda do post :quit, :slug => team.slug - end.should change(Membership,:count).by(0) - membership = Membership.find(:last) - membership.status.should == 'past hidden' - @person.approved_teams.include?(team).should_not == true + end.should change(Membership, :count).by(0) + membership = Membership.find(:last) + membership.status.should == 'past hidden' + @person.approved_teams.include?(team).should_not == true end end + + describe :add do + it "ensure add some who are not in the organisation ,it should add the new person's organisation to the team" do + mail = Object.new + PersonMailer.should_receive(:invite).and_return(mail) + mail.should_receive(:deliver) + + team = @person.teams.create(name: 'LSP', slug: 'lsp') + @organisation = Organisation.create(name: 'Google', domains: 'google.com') + post :add, :slug => team.slug, :email => 'test@google.com' + team.organisations.include?(@organisation).should == true + end + + end + end \ No newline at end of file diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index cd49dd8..d393843 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -4,19 +4,19 @@ require 'paperclip/matchers' describe Team do before(:each) do - @person = sign_in + @person = Person.create_for_email 'test@thoughworks.com' @team = @person.teams.create(name: 'LSP', slug: 'lsp') @organisation = Organisation.create(name: 'Google', domains: 'google.com') end - #describe :add_to_organisation do - # - # it 'ensure when a team add an organisation ,the organisations will change by 1' do - # - # @team.add_to_organisation - # @team.organisations.count should change_by 1 - # end - # - #end + describe :add_to_organisation do + + it 'ensure when a team add an organisation ,the organisations will change by 1' do + + @team.add_to @organisation + @team.organisations.include?(@organisation).should == true + end + + end end \ No newline at end of file