Skip to content

Join team error #391 #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.idea
.sass-cache
.vagrant
.rspec
.yardoc
/.bundle
/config/application.yml
Expand Down Expand Up @@ -56,3 +57,4 @@ git_stats
vcr_cassettes
dump
BACKUP
Guardfile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is worth adding those, so that devs can have their own local settings. Or is there a better way of doing this?

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ group :test do
# gem 'rspec-its'
gem 'capybara'
gem 'capybara-screenshot'
gem 'rack_session_access' # allows to set session from within Capybara
gem 'poltergeist' # headless js driver for Capybara that uses phantomJs
gem 'codeclimate-test-reporter', require: false
gem 'database_cleaner'
gem 'fuubar', '2.0.0.rc1'
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ GEM
choice (0.1.6)
chronic (0.10.2)
chunky_png (1.3.1)
cliver (0.3.2)
clockwork (0.7.7)
activesupport
tzinfo
Expand Down Expand Up @@ -431,6 +432,11 @@ GEM
slop (~> 3.4, >= 3.4.5)
pg (0.17.1)
pg_array_parser (0.0.9)
poltergeist (1.5.1)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
polyamorous (0.5.0)
activerecord (~> 3.0)
polyglot (0.3.5)
Expand Down Expand Up @@ -485,6 +491,9 @@ GEM
rack
rack-test (0.6.2)
rack (>= 1.0)
rack_session_access (0.1.1)
builder (>= 2.0.0)
rack (>= 1.0.0)
rails (3.2.19)
actionmailer (= 3.2.19)
actionpack (= 3.2.19)
Expand Down Expand Up @@ -700,6 +709,7 @@ GEM
addressable (>= 2.2.7)
crack (>= 0.3.2)
websocket (1.2.0)
websocket-driver (0.3.5)
xpath (2.0.0)
nokogiri (~> 1.3)
yard (0.8.7.4)
Expand Down Expand Up @@ -776,13 +786,15 @@ DEPENDENCIES
omniauth-linkedin (~> 0.0.6)
omniauth-twitter (~> 0.0.16)
pg
poltergeist
postgres_ext
pry-byebug
pry-rescue
pubnub (= 0.1.9)
puma
querystring
quiet_assets
rack_session_access
rails (~> 3.2)
rails-assets-font-awesome
rails-assets-jquery-cookie (= 1.4.0)
Expand Down
17 changes: 16 additions & 1 deletion app/assets/stylesheets/product_description.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@
margin: 0 auto 3% auto;
}

.notice {
font-size: 1.4em;
background: $green;
color: #fff;
padding: 1%;
text-align: center;
display: block;
width: 50%;
margin: 0 auto 3% auto;
}

.errors {
width: 90%;
background: $red;
Expand Down Expand Up @@ -423,6 +434,10 @@
color: #5f5f5f;
font-family: "MuseoSans-500";
}

@media screen and (min-width: 768px) {
min-height: 55px;
}
}

.selected {
Expand Down Expand Up @@ -1166,4 +1181,4 @@

}

//body end
//body end
19 changes: 9 additions & 10 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,29 @@ def new
end

def create
team_params = params.require(:team).permit(:selected, :slug, :name)
selected = team_params.fetch(:selected, nil)
team_params = params.require(:team).permit(:name, :slug, :show_similar, :join_team)
team_name = team_params.fetch(:name, '')

@teams = Team.with_similar_names(team_params[:name])

unless selected == 'false' || @teams.empty?
@new_team_name = team_params[:name]
@teams = Team.with_similar_names(team_name)
if team_params[:show_similar] == 'true' && !@teams.empty?
@new_team_name = team_name
render 'similar_teams' and return
end

if selected == 'true'
if team_params[:join_team] == 'true'
@team = Team.where(slug: team_params[:slug]).first
render :create and return
end

@team = Team.new(name: team_params[:name])
@team = Team.new(name: team_name)
if @team.save
record_event('created team')
@team.add_user(current_user)

flash.now[:notice] = "Successfully created a team #{@team.name}"
render :create
else
flash[:error] = "There was an error in creating a team #{@team.name}"
message = @team.errors.full_messages.join("\n")
flash[:error] = "There was an error in creating a team #{@team.name}\n#{message}"
end
end

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/usernames_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
class UsernamesController < ApplicationController
skip_before_action :require_registration

def index
# returns nothing if validation is run agains empty params[:id]
render nothing: true
end

def show
# allow validation to pass if it's the user's username that they're trying to validate (for edit username)
if signed_in? && current_user.username.downcase == params[:id].downcase
Expand All @@ -11,4 +16,4 @@ def show
head :ok
end
end
end
end
1 change: 1 addition & 0 deletions app/views/teams/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
= f.text_field :name

-if @team.new_record?
= hidden_field_tag('team[show_similar]', true)
.save
%input.button{ type: 'submit', value: 'Next' }
5 changes: 5 additions & 0 deletions app/views/teams/_payment.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.intro
- if @team.can_upgrade?
%h2.plans-heading Select a plan and enter payment details to get started
- unless flash[:notice].blank?
%span.notice#notice
-flash[:notice].split("\n").each do |notice|
= notice
%br
- unless flash[:error].blank?
%span.error#error
-flash[:error].split("\n").each do |error|
Expand Down
4 changes: 2 additions & 2 deletions app/views/teams/_similar_teams.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
.team-avatar
=image_tag(team.avatar_url)
%h4= link_to team.name, teamname_path(:slug => team.slug), :target => :new
= link_to 'Select', teams_path(Team.new, :team => { :slug=> team.slug, selected: true }), :remote => true, :method => :post, :class => "select"
= link_to 'Select', teams_path(:team => { :slug=> team.slug, join_team: true }), :remote => true, :method => :post, :class => "select"

- unless exact_team_exists?(@teams, @new_team_name)
.just-create-team
%h3 None of the above are my team
= link_to "Create team #{@new_team_name}", teams_path(Team.new, :team => { :name => @new_team_name, selected: false }), :remote => true, :method => :post, :class => "create-team"
= link_to "Create team #{@new_team_name}", teams_path(:team => { :name => @new_team_name }), :remote => true, :method => :post, :class => "create-team"
4 changes: 0 additions & 4 deletions app/views/teams/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
var notificationBar = $('#main-content').find('.notification-bar');
notificationBar.find('.notification-bar-inside').find('p').html("<%= flash[:error] || flash[:notice] %>");
notificationBar.show();

$('section.feature:not(.payment)').hide();
$('section.feature.payment').append('<%= escape_javascript(render :partial => "payment", :locals => {:account => @team.account || @team.build_account, :plan => @team.account.try(:current_plan)}) %>');
$('section.feature.payment').show();
Expand Down
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
Rails.application.config.sass.cache_location = "/tmp/codewall-cache/sass/"

BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] if ENV['TRUSTED_IP']
Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::DEBUG
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a cleaner way to enable more verbose output on development?

7 changes: 6 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = true
config.action_controller.allow_forgery_protection = false
config.action_mailer.delivery_method = :test
config.active_support.deprecation = :stderr
Expand All @@ -13,4 +13,9 @@

# Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
config.assets.allow_debugging = true

config.middleware.use RackSessionAccess::Middleware # alloes to set session from within Capybara

Rails.logger = Logger.new(STDOUT)
Rails.logger.level = Logger::DEBUG # provides more verbose output when testing with headless browsers in case of errors
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a cleaner way to enable more verbose output on test?

14 changes: 7 additions & 7 deletions spec/controllers/teams_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
end

context 'a team is selected from a list of similar teams' do
it 'renders a template with a choice of tariff plans when user picks a name from existing names' do
it 'renders a template with a choice of tariff plans when user joins and existing team' do
allow(Team).to receive(:where).and_return(['team_1', 'team_2'])
post :create, :team => { selected: 'true', slug: 'team_name' }, format: :js
post :create, :team => { join_team: 'true', slug: 'team_name' }, format: :js

expect(assigns[:team]).to eq('team_1')
expect(response).to render_template('create')
end

it 'renders a template with a choice of tariff plans if user picks his own team name' do
post :create, :team => { name: 'team_name', selected: 'false' }, format: :js
it 'renders a template with a choice of tariff plans if user picks supplied team name' do
post :create, :team => { name: 'team_name' }, format: :js
expect(response).to render_template('create')
end
end
Expand Down Expand Up @@ -88,13 +88,13 @@
it 'renders template with option to join' do
expect(response).to be_success
expect(response).to render_template('create')
expect(flash[:notice]).to eq("Successfully created a team team_name")
expect(flash[:notice]).to include("Successfully created a team team_name")
end

it 'renders failure notice' do
allow(team).to receive(:save).and_return(false)
response
expect(flash[:error]).to eq("There was an error in creating a team team_name")
expect(flash[:error]).to include("There was an error in creating a team team_name")
end
end

Expand All @@ -105,7 +105,7 @@
end

it 'renders a template with a list of similar teams' do
post :create, :team => { name: 'team_name' }, format: :js
post :create, :team => { name: 'team_name', show_similar: 'true' }, format: :js

expect(assigns[:new_team_name]).to eq('team_name')
expect(response).to render_template('similar_teams')
Expand Down
94 changes: 94 additions & 0 deletions spec/features/teams/team_management_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require "rails_helper"

feature "Teams management", js: true do

background do
login_as(username: 'alice', bypass_ui_login: true)
end

context 'creating a team with no similar names in db' do
scenario 'create a new team' do
create_team('TEST_TEAM')
expect(page).to have_content('Successfully created a team TEST_TEAM')
end

scenario 'add user to the newly created team' do
create_team('TEST_TEAM')

find('section.feature.payment') # ensures that we wait until the create_team action completes
visit '/alice'

expect(page).to have_content('TEST_TEAM')
end

scenario 'show payment plans selection' do
create_team('TEST_TEAM')

expect(page).to have_content('Select a plan and enter payment details to get started')
expect(page).to have_content('FREE')
expect(page).to have_content('MONTHLY')
expect(page).to have_content('ANALYTICS')
end

scenario 'redirect to team profile page when user selects FREE plan' do
create_team('TEST_TEAM')
find('section.feature.payment').find('.plans .plan.free').click_link 'Select plan'

team_id = Team.any_of({name: 'TEST_TEAM'}).first.id
expect(current_path).to eq(team_path(team_id))
end
end

context 'create a team with similar names already in db' do
let!(:team) { Team.create(name: 'EXISTING_TEAM') }

scenario 'create a new team' do
create_team('TEAM')

expect(page).to have_content('We found some matching teams')
expect(page).to have_content('EXISTING_TEAM')
expect(page).to have_content('Select')
expect(page).to have_content('None of the above are my team')
expect(page).to have_content('Create team TEAM')
end

scenario 'create a new team with originally supplied name' do
create_team('TEAM')
find('.just-create-team').click_link('Create team TEAM')
expect(page).to have_content('Successfully created a team TEAM')
end

scenario 'attempt to create a team with exact name already in db' do
create_team('EXISTING_TEAM')
find('.just-create-team').click_link('Create team EXISTING_TEAM')
expect(page).to have_content('There was an error in creating a team EXISTING_TEAM')
expect(page).to have_content('Name is already taken')
end
end

context 'join a team with a similar name' do
let!(:team) { Team.create(name: 'EXISTING_TEAM') }

scenario 'join an existing team' do
create_team('TEAM')

find('.results-list').click_link('Select')

expect(page).to have_content('Select a plan and enter payment details to get started')
expect(page).to have_content('I work at EXISTING_TEAM and just want to join the team')
expect(page).to have_content('Request to join team')
end

scenario 'request to join a team' do
create_team('TEAM')

find('.results-list').click_link('Select')
find('section.feature.payment').click_link 'Request to join team'

expect(current_path).to eq(teamname_path(team.slug))
expect(page).to have_content('We have submitted your join request to the team admin to approve')
end
end


end
16 changes: 15 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
require 'spec_helper.rb'
require 'spec_helper.rb'
require 'capybara/poltergeist'
require 'rack_session_access/capybara'

Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = 5

RSpec.configure do |config|
config.before(:example, js: :true) do
DatabaseCleaner.strategy = :truncation
ActiveRecord::Base.establish_connection
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 11 is magic - it ensures that feature specs do not hang after the first scenario, by somehow helping to switch from :transaction to :truncation scenarios. Anyone knows what exactly does it actually do?


config.include Features::GeneralHelpers, type: :feature
end
Loading