diff --git a/Gemfile.lock b/Gemfile.lock index 636aa0a..8bf66a4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,5 @@ GEM - remote: http://ruby.taobao.org/ + remote: https://rubygems.org/ specs: actionmailer (3.2.8) actionpack (= 3.2.8) diff --git a/app/assets/javascripts/organizations.js.coffee b/app/assets/javascripts/organizations.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/organizations.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/organizations.css.scss b/app/assets/stylesheets/organizations.css.scss new file mode 100644 index 0000000..3981988 --- /dev/null +++ b/app/assets/stylesheets/organizations.css.scss @@ -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/ diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb new file mode 100644 index 0000000..c501ddc --- /dev/null +++ b/app/controllers/organizations_controller.rb @@ -0,0 +1,9 @@ +class OrganizationsController < ApplicationController + def index + @organizations = Organisation.all + respond_to do |format| + format.json { render :json => @organizations } + end + end + +end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 4dd68f0..c4d05a2 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -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 diff --git a/app/helpers/organizations_helper.rb b/app/helpers/organizations_helper.rb new file mode 100644 index 0000000..24cc9a8 --- /dev/null +++ b/app/helpers/organizations_helper.rb @@ -0,0 +1,2 @@ +module OrganizationsHelper +end diff --git a/app/models/engagement.rb b/app/models/engagement.rb new file mode 100644 index 0000000..66b1a34 --- /dev/null +++ b/app/models/engagement.rb @@ -0,0 +1,4 @@ +class Engagement < ActiveRecord::Base + belongs_to :team + belongs_to :organisation +end diff --git a/app/models/organisation.rb b/app/models/organisation.rb new file mode 100644 index 0000000..84b5235 --- /dev/null +++ b/app/models/organisation.rb @@ -0,0 +1,5 @@ +class Organisation < ActiveRecord::Base + attr_accessible :name, :domains + has_many :engagements + has_many :teams, :through => :engagements +end diff --git a/app/models/team.rb b/app/models/team.rb index 03fda4e..f3b9f07 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -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={} diff --git a/app/views/teams/index.html.slim b/app/views/teams/index.html.slim index 6e2f2da..6c07699 100644 --- a/app/views/teams/index.html.slim +++ b/app/views/teams/index.html.slim @@ -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' diff --git a/config/routes.rb b/config/routes.rb index ab1063c..180a000 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,6 @@ Ocelots::Application.routes.draw do + get 'organizations' =>'organizations#index' + get 'logout' => 'home#logout', as: 'logout' post 'home/verify' => 'home#verify' diff --git a/db/migrate/20121113051443_create_organisations.rb b/db/migrate/20121113051443_create_organisations.rb new file mode 100644 index 0000000..92a79d7 --- /dev/null +++ b/db/migrate/20121113051443_create_organisations.rb @@ -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 diff --git a/db/migrate/20121113054723_create_engagements.rb b/db/migrate/20121113054723_create_engagements.rb new file mode 100644 index 0000000..17833f1 --- /dev/null +++ b/db/migrate/20121113054723_create_engagements.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index c8eb1c9..f791cbb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/lib/google_api_ext.rb b/lib/google_api_ext.rb index 2a5643e..7ad4e84 100644 --- a/lib/google_api_ext.rb +++ b/lib/google_api_ext.rb @@ -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 \ No newline at end of file diff --git a/script/create_default_organisations.rb b/script/create_default_organisations.rb new file mode 100644 index 0000000..91230e1 --- /dev/null +++ b/script/create_default_organisations.rb @@ -0,0 +1,3 @@ +Organisation.create!(name: 'ThoughtWorks', domains: 'thoughtworks.com') +Organisation.create!(name: 'Suncorp', domains: 'suncorp.com.au,suncorpbanks.com.au') + diff --git a/spec/controllers/organizations_controller_spec.rb b/spec/controllers/organizations_controller_spec.rb new file mode 100644 index 0000000..4da38d7 --- /dev/null +++ b/spec/controllers/organizations_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe OrganizationsController do + +end diff --git a/spec/controllers/teams_controller_spec.rb b/spec/controllers/teams_controller_spec.rb new file mode 100644 index 0000000..57019ab --- /dev/null +++ b/spec/controllers/teams_controller_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/helpers/organizations_helper_spec.rb b/spec/helpers/organizations_helper_spec.rb new file mode 100644 index 0000000..d5d1e85 --- /dev/null +++ b/spec/helpers/organizations_helper_spec.rb @@ -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 diff --git a/spec/models/engagement_spec.rb b/spec/models/engagement_spec.rb new file mode 100644 index 0000000..74b3554 --- /dev/null +++ b/spec/models/engagement_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Engagement do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb new file mode 100644 index 0000000..b6523da --- /dev/null +++ b/spec/models/organisation_spec.rb @@ -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