diff --git a/.gitignore b/.gitignore index c966364..82e2f53 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ public/system public/assets analyzer +coverage diff --git a/Gemfile b/Gemfile index 009ce28..110d121 100644 --- a/Gemfile +++ b/Gemfile @@ -25,5 +25,6 @@ group :development, :test do gem "rails_best_practices", "~> 1.11.1" gem "flay" gem 'rspec-rails' + gem 'simplecov' gem 'machinist' end diff --git a/Gemfile.lock b/Gemfile.lock index 8bf66a4..2b15d06 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -170,6 +170,10 @@ GEM faraday (~> 0.8.1) jwt (>= 0.1.5) multi_json (>= 1.0.0) + simplecov (0.7.1) + multi_json (~> 1.0) + simplecov-html (~> 0.7.1) + simplecov-html (0.7.1) slim (1.3.0) temple (~> 0.4.1) tilt (~> 1.3.3) @@ -220,6 +224,7 @@ DEPENDENCIES rails_best_practices (~> 1.11.1) rspec-rails sass-rails (~> 3.2.3) + simplecov slim tddium therubyracer diff --git a/Rakefile b/Rakefile index dc0de7e..18650ad 100644 --- a/Rakefile +++ b/Rakefile @@ -6,4 +6,4 @@ require File.expand_path('../config/application', __FILE__) Ocelots::Application.load_tasks -task :ci => %w(db:migrate db:test:prepare analyzer:flay analyzer:rails_best_practices spec stats) \ No newline at end of file +task :ci => %w(db:migrate db:test:prepare analyzer:flay analyzer:rails_best_practices simplecov stats) \ No newline at end of file diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 86574b7..07359dd 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -42,4 +42,18 @@ body { .social_media img { margin: 5px; +} +.team-action-form{ + float:left; + margin-left: 20px; + margin-top:16px; +} +.clear-left{ + clear:left; +} +.clear-right{ + clear:right; +} +.clear{ + clear: both; } \ No newline at end of file diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index d359c32..bd5d776 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -10,12 +10,16 @@ class TeamsController < ApplicationController end def create - organisations = params[:org_ids].map { |org_id| Organisation.find(org_id) } @teams = current_person.teams @team = Team.new params[:team].merge creator: current_person if @team.save - organisations.each{|org| org.teams << @team} + unless params[:org_ids]==nil + organisations = params[:org_ids].map { |org_id| Organisation.find(org_id) } + organisations.each{|org| org.teams << @team} + end + current_person.teams << @team + redirect_to "/teams/#{@team.slug}" else render :index @@ -27,9 +31,7 @@ class TeamsController < ApplicationController person = Person.find_by_email params[:email] person = Person.create_for_email params[:email] unless person unless person.teams.include? team - if person == current_person - Membership.create team: team, person: person - else + unless person == current_person Membership.create_pending_membership current_person, team, person end end @@ -37,6 +39,13 @@ class TeamsController < ApplicationController end end + def join + with_team do |team| + current_person.teams << team + redirect_to "/teams/#{team.slug}" + end + end + def show with_team { render :show } end @@ -53,4 +62,10 @@ class TeamsController < ApplicationController render :quiz end end + def quit + with_team do |team| + current_person.teams.delete(team) + end + redirect_to "/teams" + end end \ No newline at end of file diff --git a/app/models/membership.rb b/app/models/membership.rb index 972f725..32fe524 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -8,7 +8,7 @@ class Membership < ActiveRecord::Base belongs_to :person belongs_to :team - + delegate :email, to: :person delegate :name, to: :team, prefix: true diff --git a/app/models/person.rb b/app/models/person.rb index f42da11..4549bc8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -57,11 +57,12 @@ class Person < ActiveRecord::Base def allowed_to_view_team? team return false unless team + team.public? or blessed?(team) or team.creator == self or teams.include?(team) end def viewable_teams - Team.find(:all).select{|team| allowed_to_view_team?(team)} + Team.find(:all).select{|team| allowed_to_view_team?(team)} - approved_teams end def blessed?(team) diff --git a/app/views/teams/show.html.slim b/app/views/teams/show.html.slim index ec85a56..66f3ed2 100644 --- a/app/views/teams/show.html.slim +++ b/app/views/teams/show.html.slim @@ -11,17 +11,30 @@ - content_for :javascript_includes do = javascript_include_tag 'teams_show' -h1 = @team.name +h1 = @team.name + +- if current_person.approved_teams.include? @team + =form_tag "/teams/#{@team.slug}/quit" do + =submit_tag 'Quit Team',id:"join-team",class:"btn btn-danger " +-else + =form_tag "/teams/#{@team.slug}/join" do + =submit_tag 'Join Team',id:"join-team",class:"btn btn-primary " + +p form.form-inline label.span1.checkbox - input type="checkbox" id="show-past" past + input type="checkbox" id="show-past" + span past label.span1.checkbox - input type="checkbox" id="show-current" checked="true" current + input type="checkbox" id="show-current" checked="true" + span current label.span1.checkbox - input type="checkbox" id="show-future" future + input type="checkbox" id="show-future" + span future label.span1.checkbox - input type="checkbox" id="show-pending" pending + input type="checkbox" id="show-pending" + span pending input.span2.search-query id="show-filter" type="text" placeholder="search" div id="add_new" style="display:none;" diff --git a/config/routes.rb b/config/routes.rb index 180a000..8efc5a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,8 @@ Ocelots::Application.routes.draw do post 'teams' => 'teams#create' get 'teams/:slug' => 'teams#show' post 'teams/:slug/add' => 'teams#add' + post 'teams/:slug/join' => 'teams#join' + post 'teams/:slug/quit' => 'teams#quit' put 'membership/:id' => 'membership#update', as: 'membership' post 'membership/leave' => 'membership#leave' diff --git a/lib/tasks/analysis.rake b/lib/tasks/analysis.rake index 7f1509d..08b4a8e 100644 --- a/lib/tasks/analysis.rake +++ b/lib/tasks/analysis.rake @@ -13,13 +13,13 @@ namespace :analyzer do }) analyzer.analyze analyzer.output - fail "found bad practices, see details in " + output_file if analyzer.runner.errors.size > 37 + fail "found bad practices, see details in " + output_file if analyzer.runner.errors.size > 36 end desc "run flay and analyze code for structural similarities" task :flay do output = `flay #{FileList["lib/**/*.rb", "app/**/*.rb"].join(' ')}` fail "Error #{$?}: #{output}" unless $? == 0 - puts output + puts output end end diff --git a/lib/team_filter.rb b/lib/team_filter.rb index 0e48d69..e147c4a 100644 --- a/lib/team_filter.rb +++ b/lib/team_filter.rb @@ -1,8 +1,8 @@ module TeamFilter def with_team @team = Team.find_by_slug params[:slug] - unless current_person.blessed?(@team) - @team = nil unless current_person.teams.include?(@team) or @team.creator == current_person + unless current_person.allowed_to_view_team?(@team) + @team = nil end if @team yield @team diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 0adf90e..8bf2b2c 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -18,12 +18,28 @@ describe TeamsController do end describe :show do + it 'shows selected team' do team = @person.teams.create(name: 'LSP', slug: 'lsp') get :show, :slug => team.slug response.should be_success assigns[:team].should == team end + + it 'ensure a join button in some team we want to join' do + team = Team.create(name: 'LSP', slug: 'lsp') + get :show, :slug => team.slug + response.should be_success + 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 + + assert_select '#join-team',{:value=> 'Quit Team'} + end end describe :create do @@ -36,4 +52,32 @@ describe TeamsController do new_team.organisations.first.should == @organisation end end + + describe :join do + it 'ensure person joins a team and create a membership between person and team' do + team = Team.create(name: 'LSP', slug: 'lsp') + lambda do + post :join, :slug => team.slug + end.should change(Membership, :count).by(1) + new_membership = Membership.find(:last) + new_membership.person.allowed_to_view_team?(new_membership.team).should == true + end + + it 'ensure person can not join a team that he is not belong to the organisation of that team' do + team = Team.create(name: 'LSP', slug: 'lsp') + Organisation.find(:last).teams << team + lambda do + post :join, :slug => team.slug + end.should change(Membership, :count).by(0) + end + end + describe :quit do + it 'ensure when people quit a team then destroy a membership' do + team = Team.create(name: 'LSP', slug: 'lsp') + lambda do + post :join, :slug => team.slug + post :quit, :slug => team.slug + end.should change(Membership,:count).by(0) + end + end end \ No newline at end of file diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index cf485db..18b483d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -53,17 +53,18 @@ describe Person do let(:non_blessed_organisation) { Organisation.create(name: 'Microsoft', domains: 'microsoft.com') } let(:non_viewable_team){ non_blessed_organisation.teams.create(name: 'MS Project', slug: 'ms_project') } let(:public_team){Team.create(name: 'Public Test Team', slug: 'public.com')} - + let(:joined_team){person.teams.create(name: 'Joined Team', slug: 'joined.com')} before(:each) do viewable_team.reload public_team.reload non_viewable_team.reload end - it 'lists viewable teams but not non-viewable teams' do + it 'lists viewable teams but not non-viewable teams & joined teams' do person.viewable_teams.should be_include(viewable_team) person.viewable_teams.should_not be_include(non_viewable_team) person.viewable_teams.should be_include(public_team) + person.viewable_teams.should_not be_include(joined_team) end end end \ No newline at end of file