Skip to content

Commit 2d58319

Browse files
committed
fixed and refactoring
fix for ajax validations wihtout parameter create logig refactoring
1 parent 9f5148c commit 2d58319

File tree

10 files changed

+49
-28
lines changed

10 files changed

+49
-28
lines changed

.rspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
--require spec_helper
2-
--format documentation
2+
--format Fuubar
33
--color
4-
#--profile
4+
--profile

app/assets/stylesheets/product_description.css.scss

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@
211211
margin: 0 auto 3% auto;
212212
}
213213

214+
.notice {
215+
font-size: 1.4em;
216+
background: $green;
217+
color: #fff;
218+
padding: 1%;
219+
text-align: center;
220+
display: block;
221+
width: 50%;
222+
margin: 0 auto 3% auto;
223+
}
224+
214225
.errors {
215226
width: 90%;
216227
background: $red;
@@ -423,6 +434,10 @@
423434
color: #5f5f5f;
424435
font-family: "MuseoSans-500";
425436
}
437+
438+
@media screen and (min-width: 768px) {
439+
min-height: 55px;
440+
}
426441
}
427442

428443
.selected {
@@ -1166,4 +1181,4 @@
11661181

11671182
}
11681183

1169-
//body end
1184+
//body end

app/controllers/teams_controller.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,29 @@ def new
7878
end
7979

8080
def create
81-
team_params = params.require(:team).permit(:selected, :slug, :name)
82-
selected = team_params.fetch(:selected, nil)
81+
team_params = params.require(:team).permit(:name, :slug, :show_similar, :join_team)
82+
team_name = team_params.fetch(:name, '')
8383

84-
@teams = Team.with_similar_names(team_params[:name])
85-
86-
unless selected == 'false' || @teams.empty?
87-
@new_team_name = team_params[:name]
84+
@teams = Team.with_similar_names(team_name)
85+
if team_params[:show_similar] == 'true' && !@teams.empty?
86+
@new_team_name = team_name
8887
render 'similar_teams' and return
8988
end
9089

91-
if selected == 'true'
90+
if team_params[:join_team] == 'true'
9291
@team = Team.where(slug: team_params[:slug]).first
9392
render :create and return
9493
end
9594

96-
@team = Team.new(name: team_params[:name])
95+
@team = Team.new(name: team_name)
9796
if @team.save
9897
record_event('created team')
9998
@team.add_user(current_user)
10099

101100
flash.now[:notice] = "Successfully created a team #{@team.name}"
102-
render :create
103101
else
104-
flash[:error] = "There was an error in creating a team #{@team.name}"
102+
message = @team.errors.full_messages.join("\n")
103+
flash[:error] = "There was an error in creating a team #{@team.name}\n#{message}"
105104
end
106105
end
107106

app/controllers/usernames_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
class UsernamesController < ApplicationController
22
skip_before_action :require_registration
33

4+
def index
5+
# returns nothing if validation is run agains empty params[:id]
6+
render nothing: true
7+
end
8+
49
def show
510
# allow validation to pass if it's the user's username that they're trying to validate (for edit username)
611
if signed_in? && current_user.username.downcase == params[:id].downcase
@@ -11,4 +16,4 @@ def show
1116
head :ok
1217
end
1318
end
14-
end
19+
end

app/views/teams/_form.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
= f.text_field :name
88

99
-if @team.new_record?
10+
= hidden_field_tag('team[show_similar]', true)
1011
.save
1112
%input.button{ type: 'submit', value: 'Next' }

app/views/teams/_payment.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
.intro
22
- if @team.can_upgrade?
33
%h2.plans-heading Select a plan and enter payment details to get started
4+
- unless flash[:notice].blank?
5+
%span.notice#notice
6+
-flash[:notice].split("\n").each do |notice|
7+
= notice
8+
%br
49
- unless flash[:error].blank?
510
%span.error#error
611
-flash[:error].split("\n").each do |error|

app/views/teams/_similar_teams.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
.team-avatar
88
=image_tag(team.avatar_url)
99
%h4= link_to team.name, teamname_path(:slug => team.slug), :target => :new
10-
= link_to 'Select', teams_path(Team.new, :team => { :slug=> team.slug, selected: true }), :remote => true, :method => :post, :class => "select"
10+
= link_to 'Select', teams_path(:team => { :slug=> team.slug, join_team: true }), :remote => true, :method => :post, :class => "select"
1111

1212
- unless exact_team_exists?(@teams, @new_team_name)
1313
.just-create-team
1414
%h3 None of the above are my team
15-
= 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"
15+
= link_to "Create team #{@new_team_name}", teams_path(:team => { :name => @new_team_name }), :remote => true, :method => :post, :class => "create-team"

app/views/teams/create.js.erb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
var notificationBar = $('#main-content').find('.notification-bar');
2-
notificationBar.find('.notification-bar-inside').find('p').html("<%= flash[:error] || flash[:notice] %>");
3-
notificationBar.show();
4-
51
$('section.feature:not(.payment)').hide();
62
$('section.feature.payment').append('<%= escape_javascript(render :partial => "payment", :locals => {:account => @team.account || @team.build_account, :plan => @team.account.try(:current_plan)}) %>');
73
$('section.feature.payment').show();

config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
config.middleware.use RackSessionAccess::Middleware # alloes to set session from within Capybara
1818

1919
Rails.logger = Logger.new(STDOUT)
20-
Rails.logger.level = Logger::DEBUG # provides more verbose output testing with headless browsers in case of errors
20+
Rails.logger.level = Logger::DEBUG # provides more verbose output when testing with headless browsers in case of errors
2121
end

spec/controllers/teams_controller_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@
4747
end
4848

4949
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 picks a name from existing names' do
50+
it 'renders a template with a choice of tariff plans when user joins and existing team' do
5151
allow(Team).to receive(:where).and_return(['team_1', 'team_2'])
52-
post :create, :team => { selected: 'true', slug: 'team_name' }, format: :js
52+
post :create, :team => { join_team: 'true', slug: 'team_name' }, format: :js
5353

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

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
58+
it 'renders a template with a choice of tariff plans if user picks supplied team name' do
59+
post :create, :team => { name: 'team_name' }, format: :js
6060
expect(response).to render_template('create')
6161
end
6262
end
@@ -88,13 +88,13 @@
8888
it 'renders template with option to join' do
8989
expect(response).to be_success
9090
expect(response).to render_template('create')
91-
expect(flash[:notice]).to eq("Successfully created a team team_name")
91+
expect(flash[:notice]).to include("Successfully created a team team_name")
9292
end
9393

9494
it 'renders failure notice' do
9595
allow(team).to receive(:save).and_return(false)
9696
response
97-
expect(flash[:error]).to eq("There was an error in creating a team team_name")
97+
expect(flash[:error]).to include("There was an error in creating a team team_name")
9898
end
9999
end
100100

@@ -105,7 +105,7 @@
105105
end
106106

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

110110
expect(assigns[:new_team_name]).to eq('team_name')
111111
expect(response).to render_template('similar_teams')

0 commit comments

Comments
 (0)