Merge pull request #8 from wahyd4/master

Now users can join and quit teams
This commit is contained in:
Jeff Xiong
2012-11-14 02:23:40 -08:00
14 changed files with 116 additions and 19 deletions
+1
View File
@@ -18,3 +18,4 @@ public/system
public/assets
analyzer
coverage
+1
View File
@@ -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
+5
View File
@@ -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
+1 -1
View File
@@ -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)
task :ci => %w(db:migrate db:test:prepare analyzer:flay analyzer:rails_best_practices simplecov stats)
@@ -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;
}
+20 -5
View File
@@ -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
+1 -1
View File
@@ -8,7 +8,7 @@ class Membership < ActiveRecord::Base
belongs_to :person
belongs_to :team
delegate :email, to: :person
delegate :name, to: :team, prefix: true
+2 -1
View File
@@ -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)
+18 -5
View File
@@ -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;"
+2
View File
@@ -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'
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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
+44
View File
@@ -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
+3 -2
View File
@@ -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