mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
@@ -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/
|
||||
@@ -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/
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,2 @@
|
||||
module TestHelper
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user