diff --git a/app/assets/javascripts/test.js.coffee b/app/assets/javascripts/test.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/test.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/test.css.scss b/app/assets/stylesheets/test.css.scss new file mode 100644 index 0000000..97f8988 --- /dev/null +++ b/app/assets/stylesheets/test.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the test controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index bd5d776..bbece3f 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -4,7 +4,7 @@ class TeamsController < ApplicationController include TeamFilter def index - @memberships = current_person.memberships + @memberships = current_person.memberships.select{|membership| membership.ended==nil} @team = Team.new @organisations = Organisation.find(:all) end @@ -39,13 +39,6 @@ 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 @@ -62,9 +55,17 @@ class TeamsController < ApplicationController render :quiz end end + + def join + with_team do |team| + current_person.join team + redirect_to "/teams/#{team.slug}" + end + end + def quit with_team do |team| - current_person.teams.delete(team) + current_person.leave team end redirect_to "/teams" end diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb new file mode 100644 index 0000000..2b7bb73 --- /dev/null +++ b/app/controllers/test_controller.rb @@ -0,0 +1,10 @@ +class TestController < ApplicationController + skip_before_filter :require_login, :only => :test_login + + def test_login + if Rails.env.test? || Rails.env.development? + session[:email] = "test@gmail.com" + redirect_to "/" + end + end +end diff --git a/app/helpers/teams_helper.rb b/app/helpers/teams_helper.rb index 42ff0aa..50e9c11 100644 --- a/app/helpers/teams_helper.rb +++ b/app/helpers/teams_helper.rb @@ -1,6 +1,5 @@ module TeamsHelper def membership_partial membership - return 'my_membership' if membership.person == @current_person membership.pending? ? 'pending_membership' : 'approved_membership' end end \ No newline at end of file diff --git a/app/helpers/test_helper.rb b/app/helpers/test_helper.rb new file mode 100644 index 0000000..09b6d50 --- /dev/null +++ b/app/helpers/test_helper.rb @@ -0,0 +1,2 @@ +module TestHelper +end diff --git a/app/models/membership.rb b/app/models/membership.rb index 0c9c20f..9314497 100644 --- a/app/models/membership.rb +++ b/app/models/membership.rb @@ -12,7 +12,7 @@ class Membership < ActiveRecord::Base delegate :track, :photo, :gravatar_url, to: :person, prefix: true delegate :name, :slug, :description, to: :team, prefix: true - scope :approved, where('pending_approval_token is null') + scope :approved, where('pending_approval_token is null and ended is null') def self.create_pending_membership inviter, team, person membership = Membership.create team: team, @@ -23,7 +23,7 @@ class Membership < ActiveRecord::Base def status return 'future hidden' if started and started > Date.today - return 'past hidden' if ended and Date.today > ended + return 'past hidden' if ended and Date.today >= ended return 'silent hidden' if hidden 'current' end @@ -34,6 +34,13 @@ class Membership < ActiveRecord::Base def approve update_attributes pending_approval_token: nil + if ended + update_attributes ended: nil + end + end + + def leave + update_attributes ended: Date.today end def self.api_attributes_for user diff --git a/app/models/person.rb b/app/models/person.rb index 46b6d21..7be0ed0 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -76,4 +76,18 @@ class Person < ActiveRecord::Base def email_domain email.split('@').last end + + def leave (team) + Membership.where(team_id: team.id,person_id: id).first.leave + end + + def join(team) + if Membership.where(team_id: team.id,person_id: id).empty? + teams << team + else + Membership.where(team_id: team.id,person_id: id).first.approve + end + + end + end \ No newline at end of file diff --git a/app/views/teams/index.html.slim b/app/views/teams/index.html.slim index f001c88..2ca736c 100644 --- a/app/views/teams/index.html.slim +++ b/app/views/teams/index.html.slim @@ -47,7 +47,7 @@ div id="add_new" style="display:none;" div.clearfix - current_person.viewable_teams.each do |team| a href="/teams/#{team.slug}" - span.badge.badge-info Viewable + span.label.label-info style="float:left" Viewable div.hero-unit.highlight div.row div.span4 diff --git a/app/views/test/test_login.html.slim b/app/views/test/test_login.html.slim new file mode 100644 index 0000000..e69de29 diff --git a/config/routes.rb b/config/routes.rb index 8efc5a9..9e88864 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -44,5 +44,7 @@ Ocelots::Application.routes.draw do get 'antechamber/:slug' => 'antechamber#index' post 'antechamber/:slug' => 'antechamber#create' + get 'test_login' => 'test#test_login' + root to: 'home#index' end \ No newline at end of file diff --git a/features/main_process.feature b/features/main_process.feature index 733bb5b..1f505aa 100644 --- a/features/main_process.feature +++ b/features/main_process.feature @@ -6,4 +6,7 @@ Feature: Main process of Ocelots Scenario: Go to home page Given I am not signed in When I go to home page - Then I should see sign in buttons + Then I should click login link + Then I see list of team + Then I should add a team + Then I should quit that team diff --git a/features/step_definitions/main_process.rb b/features/step_definitions/main_process.rb index fb02f1b..439cd5b 100644 --- a/features/step_definitions/main_process.rb +++ b/features/step_definitions/main_process.rb @@ -6,6 +6,21 @@ When /^I go to home page$/ do visit '/' end -Then /^I should see sign in buttons$/ do - # TODO: assertion here +Then /^I should click login link$/ do + page.execute_script("window.location.href='/test_login'") +end + +Then /^I see list of team$/ do + page.should have_content('team') +end + +Then /^I should add a team$/ do + click_link('add team') + fill_in 'Team Name', :with => 'Test_team' + fill_in 'URL', :with => 'Test_URL' + click_button 'Create' +end + +Then /^I should quit that team$/ do + click_button 'Quit Team' end diff --git a/lib/google_api_ext.rb b/lib/google_api_ext.rb index aca9feb..5a1ec39 100644 --- a/lib/google_api_ext.rb +++ b/lib/google_api_ext.rb @@ -19,7 +19,7 @@ Google::APIClient.class_eval do origin: 'iocelots.com', client_id: '1030433741080.apps.googleusercontent.com', client_secret: 'RAQdt17GKweBtQzOCq6Dp965', - redirect_uri: 'http://www.iocelots.com/home/verify_g_callback' + redirect_uri: 'http://iocelots.com/home/verify_g_callback' } ] client_configuration = configurations.find{|conf| origin.include?(conf[:origin])} diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb index 8bf2b2c..22d2596 100644 --- a/spec/controllers/teams_controller_spec.rb +++ b/spec/controllers/teams_controller_spec.rb @@ -54,6 +54,7 @@ describe TeamsController do 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 @@ -61,6 +62,15 @@ describe TeamsController do 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 when person quit from a team then join it again,and it will not disappear in past situation' do + team = Team.create(name: 'LSP', slug: 'lsp') + post :join ,:slug =>team.slug + post :quit, :slug => team.slug + post :join ,:slug =>team.slug + membership = Membership.find(:last).ended.should == nil end it 'ensure person can not join a team that he is not belong to the organisation of that team' do @@ -72,12 +82,15 @@ describe TeamsController do end end describe :quit do - it 'ensure when people quit a team then destroy a membership' do + it 'ensure when people quit a team then set the relationship ended,and the team should removed from approved team' do team = Team.create(name: 'LSP', slug: 'lsp') + post :join, :slug => team.slug lambda do - post :join, :slug => team.slug post :quit, :slug => team.slug end.should change(Membership,:count).by(0) + membership = Membership.find(:last) + membership.status.should == 'past hidden' + @person.approved_teams.include?(team).should_not == true end end end \ No newline at end of file diff --git a/spec/controllers/test_controller_spec.rb b/spec/controllers/test_controller_spec.rb new file mode 100644 index 0000000..622e349 --- /dev/null +++ b/spec/controllers/test_controller_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe TestController do + + describe :test_login do + it 'ensure person login with test email if Rails environment is test' do + get :test_login + session[:email] == 'test@gmail.com' + assert_redirected_to '/' + end + end +end diff --git a/spec/helpers/test_helper_spec.rb b/spec/helpers/test_helper_spec.rb new file mode 100644 index 0000000..0785ef5 --- /dev/null +++ b/spec/helpers/test_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TestHelper. For example: +# +# describe TestHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe TestHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/lib/google_api_client_spec.rb b/spec/lib/google_api_client_spec.rb index 2194452..e18e621 100644 --- a/spec/lib/google_api_client_spec.rb +++ b/spec/lib/google_api_client_spec.rb @@ -14,7 +14,7 @@ describe Google::APIClient do it 'builds google api client for production' do client = Google::APIClient.build('iocelots.com') - client.authorization.redirect_uri.to_s.should == 'http://www.iocelots.com/home/verify_g_callback' + client.authorization.redirect_uri.to_s.should == 'http://iocelots.com/home/verify_g_callback' end end end \ No newline at end of file diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 18b483d..b7f86c1 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -67,4 +67,18 @@ describe Person do person.viewable_teams.should_not be_include(joined_team) end end + + describe 'person team membership' do + + it 'leave team correctly' do + team = Team.create(name: 'LSP', slug: 'lsp') + person = Person.create_for_email("user@email.com") + person.teams << team + + person.leave(team) + membership = Membership.find(:last) + membership.status.should == 'past hidden' + end + + end end \ No newline at end of file