mirror of
https://github.com/wahyd4/ocelots.git
synced 2026-08-09 04:56:21 +10:00
add a concept of organization
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
GEM
|
||||
remote: http://ruby.taobao.org/
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (3.2.8)
|
||||
actionpack (= 3.2.8)
|
||||
|
||||
@@ -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 organizations controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@@ -0,0 +1,9 @@
|
||||
class OrganizationsController < ApplicationController
|
||||
def index
|
||||
@organizations = Organisation.all
|
||||
respond_to do |format|
|
||||
format.json { render :json => @organizations }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -6,12 +6,16 @@ class TeamsController < ApplicationController
|
||||
def index
|
||||
@memberships = current_person.memberships
|
||||
@team = Team.new
|
||||
@organisations = Organisation.find(:all)
|
||||
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|}
|
||||
redirect_to "/teams/#{@team.slug}"
|
||||
else
|
||||
render :index
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
module OrganizationsHelper
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
class Engagement < ActiveRecord::Base
|
||||
belongs_to :team
|
||||
belongs_to :organisation
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Organisation < ActiveRecord::Base
|
||||
attr_accessible :name, :domains
|
||||
has_many :engagements
|
||||
has_many :teams, :through => :engagements
|
||||
end
|
||||
@@ -8,6 +8,8 @@ class Team < ActiveRecord::Base
|
||||
has_many :memberships
|
||||
has_many :people, through: :memberships
|
||||
has_many :messages
|
||||
has_many :engagements
|
||||
has_many :organisations, through: :engagements
|
||||
belongs_to :creator, class_name: 'Person'
|
||||
|
||||
def api_attributes params={}
|
||||
|
||||
@@ -12,7 +12,15 @@ div id="add_new" style="display:none;"
|
||||
div.control-group
|
||||
label.control-label for="team_slug" URL
|
||||
div.controls
|
||||
p http://ocelots.herokuapp.com/#{form.text_field :slug}
|
||||
p http://iocelots.com/#{form.text_field :slug}
|
||||
div.controls id="organizations"
|
||||
ul
|
||||
- @organisations.each do |org|
|
||||
li
|
||||
= check_box_tag "org_ids[]", org.id, id="org_ids_#{org.id}"
|
||||
= org.name
|
||||
|
||||
|
||||
div.form-actions
|
||||
= form.submit 'Create', class: 'btn'
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
Ocelots::Application.routes.draw do
|
||||
get 'organizations' =>'organizations#index'
|
||||
|
||||
get 'logout' => 'home#logout', as: 'logout'
|
||||
|
||||
post 'home/verify' => 'home#verify'
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class CreateOrganisations < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :organisations do |t|
|
||||
t.string :name
|
||||
t.string :domains
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class CreateEngagements < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :engagements do |t|
|
||||
t.integer :organisation_id
|
||||
t.integer :team_id
|
||||
end
|
||||
end
|
||||
end
|
||||
+13
-1
@@ -11,7 +11,12 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121018121645) do
|
||||
ActiveRecord::Schema.define(:version => 20121113054723) do
|
||||
|
||||
create_table "engagements", :force => true do |t|
|
||||
t.integer "organisation_id"
|
||||
t.integer "team_id"
|
||||
end
|
||||
|
||||
create_table "facts", :force => true do |t|
|
||||
t.integer "person_id"
|
||||
@@ -42,6 +47,13 @@ ActiveRecord::Schema.define(:version => 20121018121645) do
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "organisations", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "domains"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "people", :force => true do |t|
|
||||
t.string "account"
|
||||
t.string "full_name"
|
||||
|
||||
@@ -6,7 +6,7 @@ Google::APIClient.class_eval do
|
||||
client.authorization.client_id = '83201658099-d921h8ub8ugrus8j1l923m2ke98h2lo1.apps.googleusercontent.com'
|
||||
client.authorization.client_secret = 'A6_wExaNj5_C0QdSF1zZJ4bB'
|
||||
client.authorization.scope = 'https://www.googleapis.com/auth/userinfo.email'
|
||||
client.authorization.redirect_uri = 'http://iocelots.com/verify_g_callback'
|
||||
client.authorization.redirect_uri = 'http://iocelots.com/home/verify_g_callback'
|
||||
client
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
Organisation.create!(name: 'ThoughtWorks', domains: 'thoughtworks.com')
|
||||
Organisation.create!(name: 'Suncorp', domains: 'suncorp.com.au,suncorpbanks.com.au')
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe OrganizationsController do
|
||||
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe TeamsController do
|
||||
before(:each) do
|
||||
session[:email] = 'do.not.make.me.test@gmail.com'
|
||||
@organisation = Organisation.create(name: 'ThoughtWorks', domains: 'ThoughtWorks.com')
|
||||
end
|
||||
|
||||
describe :index do
|
||||
it 'fetches all organisations' do
|
||||
get :index
|
||||
all_organisations = assigns[:organisations]
|
||||
all_organisations.should_not be_nil
|
||||
all_organisations.should_not be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe :create do
|
||||
it 'creates team with organisations' do
|
||||
lambda do
|
||||
post :create, team: {name: 'LSP', slug: 'lsp'}, org_ids: [@organisation.id.to_s]
|
||||
end.should change(Team, :count).by(1)
|
||||
new_team = Team.find(:last)
|
||||
new_team.name.should == 'LSP'
|
||||
new_team.organisations.should be_include(@organisation)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the OrganizationsHelper. For example:
|
||||
#
|
||||
# describe OrganizationsHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# helper.concat_strings("this","that").should == "this that"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
describe OrganizationsHelper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Engagement do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Organisation do
|
||||
it 'associates with multiple teams' do
|
||||
tw = Organisation.create(name: 'ThoughtWorks')
|
||||
tw.teams.create(name: 'Suncorp LSP')
|
||||
tw.teams.should have(1).team
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user