|
39 | 39 | end
|
40 | 40 | end
|
41 | 41 |
|
42 |
| - describe "#create" , focus: true do |
43 |
| - let(:team) { Fabricate.build(:team) } |
44 |
| - |
45 |
| - it 'renders an error message if action was unsuccessful' do |
| 42 | + describe "#create" do |
| 43 | + let(:team) { Fabricate.build(:team, name: 'team_name') } |
46 | 44 |
|
| 45 | + before do |
| 46 | + allow(Team).to receive(:with_similar_names).and_return([]) |
47 | 47 | end
|
48 | 48 |
|
49 | 49 | context 'a team is selected from a list of similar teams' do
|
50 |
| - it 'renders a template with a choice of tariff plans when user selects a team' do |
| 50 | + it 'renders a template with a choice of tariff plans when user picks a name from existing names' do |
| 51 | + allow(Team).to receive(:where).and_return(['team_1', 'team_2']) |
51 | 52 | post :create, :team => { selected: 'true', slug: 'team_name' }, format: :js
|
| 53 | + |
| 54 | + expect(assigns[:team]).to eq('team_1') |
| 55 | + expect(response).to render_template('create') |
| 56 | + end |
| 57 | + |
| 58 | + it 'renders a template with a choice of tariff plans if user picks his own team name' do |
| 59 | + post :create, :team => { name: 'team_name', selected: 'false' }, format: :js |
52 | 60 | expect(response).to render_template('create')
|
53 | 61 | end
|
54 | 62 | end
|
|
57 | 65 | let(:response) { post :create, :team => { name: 'team_name' }, format: :js }
|
58 | 66 |
|
59 | 67 | before do
|
60 |
| - allow(controller).to receive(:get_similar_teams).and_return(nil) |
61 |
| - |
62 | 68 | allow(Team).to receive(:new).and_return(team)
|
63 | 69 | allow(team).to receive(:save).and_return(true)
|
64 | 70 | allow(team).to receive(:add_user).and_return(true)
|
|
82 | 88 | it 'renders template with option to join' do
|
83 | 89 | expect(response).to be_success
|
84 | 90 | expect(response).to render_template('create')
|
| 91 | + expect(flash[:notice]).to eq("Successfully created a team team_name") |
| 92 | + end |
| 93 | + |
| 94 | + it 'renders failure notice' do |
| 95 | + allow(team).to receive(:save).and_return(false) |
| 96 | + response |
| 97 | + expect(flash[:error]).to eq("There was an error in creating a team team_name") |
85 | 98 | end
|
86 | 99 | end
|
87 | 100 |
|
|
93 | 106 |
|
94 | 107 | it 'renders a template with a list of similar teams' do
|
95 | 108 | post :create, :team => { name: 'team_name' }, format: :js
|
| 109 | + |
| 110 | + expect(assigns[:new_team_name]).to eq('team_name') |
96 | 111 | expect(response).to render_template('similar_teams')
|
97 | 112 | end
|
98 | 113 | end
|
|
0 commit comments