From bb8799fe1d5b6ee7b905723382c8e3634d2cd14d Mon Sep 17 00:00:00 2001 From: chidumaga Date: Thu, 25 Jun 2015 20:08:08 +0100 Subject: [PATCH 01/16] displays next pair --- app/controllers/users_controller.rb | 1 + app/views/users/index.html.erb | 1 + spec/feature/user_feature_spec.rb | 15 +++++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 spec/feature/user_feature_spec.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 340704d..89e2ec5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -5,6 +5,7 @@ class UsersController < ApplicationController # GET /users.json def index @users = User.all + @next_pair = User.first.username end # GET /users/1 diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index f0d3823..8eaa85b 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -14,6 +14,7 @@ + <%= "You are paired with #{@next_pair}" %> <% @users.each do |user| %> <%= user.username %> diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb new file mode 100644 index 0000000..587770d --- /dev/null +++ b/spec/feature/user_feature_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +feature 'As a Pairmiscuous user' do + + before(:each) do + User.create(username: "Molly") + User.create(username: "Rocco") + User.create(username: "Tim") + end + + scenario 'pair is shown' do + visit users_path + expect(page).to have_content("You are paired with Molly"); + end +end \ No newline at end of file From 532b06417f780039d2bfb5345c05729485e37a5f Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 11:38:55 +0100 Subject: [PATCH 02/16] first test passing --- Gemfile.lock | 3 + app/helpers/pairings_helper.rb | 21 ++ coverage/.last_run.json | 5 + coverage/.resultset.json | 377 +++++++++++++++++++++++++++++++++ coverage/.resultset.json.lock | 0 spec/pair_selection_spec.rb | 25 +++ 6 files changed, 431 insertions(+) create mode 100644 app/helpers/pairings_helper.rb create mode 100644 coverage/.last_run.json create mode 100644 coverage/.resultset.json create mode 100644 coverage/.resultset.json.lock create mode 100644 spec/pair_selection_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 79e9499..97ce11e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,3 +220,6 @@ DEPENDENCIES turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) + +BUNDLED WITH + 1.10.4 diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb new file mode 100644 index 0000000..2ef9e61 --- /dev/null +++ b/app/helpers/pairings_helper.rb @@ -0,0 +1,21 @@ +module PairingsHelper + + # Return an array of potential partners in descending order of attractiveness + def pair_me(primary_user, cohort, cohort_pair_history = []) + # Filter the available partners from the current cohort + # Next version should filter users already paired for today in pair history + cohort_users = User.where(cohort_id: cohort.id).find_each.to_a + available_users = cohort_users.reject do |user| + user == primary_user + end + + return available_users.shuffle + + end + + # def assign_pairs(cohort_name) + # # this is the method used elsewhere + # # odd number should return a final pair of one person + # end + +end diff --git a/coverage/.last_run.json b/coverage/.last_run.json new file mode 100644 index 0000000..3cb5e70 --- /dev/null +++ b/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "covered_percent": 100.0 + } +} diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 0000000..1e781e4 --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,377 @@ +{ + "RSpec": { + "coverage": { + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/spec/dummy_test_spec.rb": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/spec/rails_helper.rb": [ + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + 1, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/environment.rb": [ + null, + 1, + null, + null, + 1 + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/application.rb": [ + 1, + null, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + null, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/boot.rb": [ + 1, + null, + 1 + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/environments/test.rb": [ + 1, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/assets.rb": [ + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/backtrace_silencers.rb": [ + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/cookies_serializer.rb": [ + null, + null, + 1 + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ + null, + null, + null, + 1 + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/inflections.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/mime_types.rb": [ + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/session_store.rb": [ + null, + null, + 1 + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/wrap_parameters.rb": [ + null, + null, + null, + null, + null, + null, + 1, + 1, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/routes.rb": [ + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/helpers/application_helper.rb": [ + 1, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/helpers/pairings_helper.rb": [ + 1, + null, + null, + 1, + null, + null, + 1, + 1, + 2, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/helpers/users_helper.rb": [ + 1, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/spec/pair_selection_spec.rb": [ + 1, + 1, + 1, + null, + 1, + null, + 1, + null, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/models/cohort.rb": [ + 1, + null, + 1, + 1, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/models/user.rb": [ + 1, + null, + 1, + 1, + 1, + null, + null + ] + }, + "timestamp": 1435315085 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 0000000..e69de29 diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb new file mode 100644 index 0000000..e58175e --- /dev/null +++ b/spec/pair_selection_spec.rb @@ -0,0 +1,25 @@ +require 'rails_helper' +require './app/helpers/pairings_helper' +include PairingsHelper + +describe 'Create a pair' do + + it 'should return an available pair partner' do + # puts "Cohorts: #{Cohort.all.length}" + # puts "Users: #{User.all.length}" + # puts "Pairings: #{Pairing.all.length}" + + cohort = Cohort.create() + user = [] + user[1] = cohort.users.create() + user[2] = cohort.users.create() + + result = pair_me(user[1],cohort) + expect(result).to eq([user[2]]) + end + +end + +describe 'Pair up a cohort' do + # to be written +end From ae2a328c2d60e736ac675d3cf344fc7209921f6e Mon Sep 17 00:00:00 2001 From: Mollie Stephenson Date: Fri, 26 Jun 2015 11:48:45 +0100 Subject: [PATCH 03/16] Adds a new test --- app/views/users/index.html.erb | 1 + db/schema.rb | 25 ++++++++++++++++++++++++- spec/feature/user_feature_spec.rb | 19 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 8eaa85b..bcc1e5c 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -15,6 +15,7 @@ <%= "You are paired with #{@next_pair}" %> + <% @users.each do |user| %> <%= user.username %> diff --git a/db/schema.rb b/db/schema.rb index f110a47..094a28d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,28 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150625183707) do +ActiveRecord::Schema.define(version: 20150625213059) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "cohorts", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "pairings", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "pair_id" + t.integer "user_id" + t.integer "cohort_id" + end + + add_index "pairings", ["cohort_id"], name: "index_pairings_on_cohort_id", using: :btree + add_index "pairings", ["user_id"], name: "index_pairings_on_user_id", using: :btree + create_table "users", force: :cascade do |t| t.string "username" t.string "full_name" @@ -23,6 +40,12 @@ t.string "slack_username" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "cohort_id" end + add_index "users", ["cohort_id"], name: "index_users_on_cohort_id", using: :btree + + add_foreign_key "pairings", "cohorts" + add_foreign_key "pairings", "users" + add_foreign_key "users", "cohorts" end diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb index 587770d..9bf4a87 100644 --- a/spec/feature/user_feature_spec.rb +++ b/spec/feature/user_feature_spec.rb @@ -1,15 +1,32 @@ require 'rails_helper' + feature 'As a Pairmiscuous user' do before(:each) do User.create(username: "Molly") User.create(username: "Rocco") User.create(username: "Tim") + User.create(username: 'Chidu') end scenario 'pair is shown' do visit users_path expect(page).to have_content("You are paired with Molly"); end -end \ No newline at end of file + + scenario 'accepting a pair' do + sign_up('Rocco', 'rocco') + click_link('Back') + click_button('Accept') + expect(page).to have_content('Rocco and Chidu') + expect(page).to have_content('Congratulations on pairing.') + end + + def sign_up(username, name) + visit new_user_path + fill_in('Full name', with: name) + fill_in('Username', with: username) + click_button('Create User') + end +end From 5f3f82ec61b2e3d72c3565bd39e34ccea114328a Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 11:52:00 +0100 Subject: [PATCH 04/16] second test passing, pair_me returns an array --- coverage/.resultset.json | 19 ++++++++++++++----- spec/pair_selection_spec.rb | 13 ++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 1e781e4..eb51e9d 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -307,12 +307,12 @@ 1, null, null, - 1, - 1, 2, + 2, + 22, null, null, - 1, + 2, null, null, null, @@ -336,21 +336,30 @@ null, 1, null, + 1, + 1, + 1, + 1, null, + 1, + 1, null, null, 1, + null, 1, 1, - 1, + 21, null, 1, 1, + 20, 1, null, null, null, null, + null, 1, null, null @@ -372,6 +381,6 @@ null ] }, - "timestamp": 1435315085 + "timestamp": 1435315834 } } diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index e58175e..1ffdc98 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -5,9 +5,6 @@ describe 'Create a pair' do it 'should return an available pair partner' do - # puts "Cohorts: #{Cohort.all.length}" - # puts "Users: #{User.all.length}" - # puts "Pairings: #{Pairing.all.length}" cohort = Cohort.create() user = [] @@ -18,6 +15,16 @@ expect(result).to eq([user[2]]) end + it 'should return all available partners excluding the user being matched' do + cohort = Cohort.create() + user = [] + 20.times {user << cohort.users.create()} + result = pair_me(user[0],cohort).sort + expect(result.length).to eq(19) + user[1..19].each { |use| expect(result).to include(use) } + expect(result).not_to include(user[0]) + end + end describe 'Pair up a cohort' do From ed43ad1cc7bed271ba6378c5982e70a9bad843ce Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 12:00:08 +0100 Subject: [PATCH 05/16] added test helper for setup --- coverage/.resultset.json | 20 +++++++++++++++----- spec/pair_selection_spec.rb | 33 ++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/coverage/.resultset.json b/coverage/.resultset.json index eb51e9d..02c6a3e 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -335,21 +335,28 @@ 1, null, 1, + 2, + 2, + 24, + null, null, 1, 1, + null, + null, + null, + null, + null, + null, 1, 1, null, + null, 1, 1, null, null, - 1, null, - 1, - 1, - 21, null, 1, 1, @@ -357,6 +364,9 @@ 1, null, null, + 1, + null, + null, null, null, null, @@ -381,6 +391,6 @@ null ] }, - "timestamp": 1435315834 + "timestamp": 1435316372 } } diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index 1ffdc98..b101877 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -4,25 +4,28 @@ describe 'Create a pair' do - it 'should return an available pair partner' do - - cohort = Cohort.create() - user = [] - user[1] = cohort.users.create() - user[2] = cohort.users.create() + def create_test_cohort(cohort_size) + @cohort = Cohort.create() + @user = [] + cohort_size.times {@user << @cohort.users.create()} + end - result = pair_me(user[1],cohort) - expect(result).to eq([user[2]]) + it 'should return a cohort pair partner' do + create_test_cohort(2) + result = pair_me(@user[0],@cohort) + expect(result).to eq([@user[1]]) end - it 'should return all available partners excluding the user being matched' do - cohort = Cohort.create() - user = [] - 20.times {user << cohort.users.create()} - result = pair_me(user[0],cohort).sort + it 'should return all cohort partners excluding the user being matched' do + create_test_cohort(20) + result = pair_me(@user[0],@cohort).sort expect(result.length).to eq(19) - user[1..19].each { |use| expect(result).to include(use) } - expect(result).not_to include(user[0]) + @user[1..19].each { |use| expect(result).to include(use) } + expect(result).not_to include(@user[0]) + end + + it 'should return all cohort partners excluding those already paired today' do + end end From d752ff80a6be16d55ea27b986f0e1030444671c4 Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 12:34:55 +0100 Subject: [PATCH 06/16] prior to pull from master --- app/helpers/pairings_helper.rb | 2 +- spec/pair_selection_spec.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index 2ef9e61..1683067 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -14,7 +14,7 @@ def pair_me(primary_user, cohort, cohort_pair_history = []) end # def assign_pairs(cohort_name) - # # this is the method used elsewhere + # # this is a method used elsewhere # # odd number should return a final pair of one person # end diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index b101877..ae21435 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -25,6 +25,7 @@ def create_test_cohort(cohort_size) end it 'should return all cohort partners excluding those already paired today' do + create_test_cohort(20) end From 56fc2d60eea9e11aa45cee906dceff81704f6ca0 Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 13:36:54 +0100 Subject: [PATCH 07/16] failing test for alrady paired today --- app/helpers/pairings_helper.rb | 34 ++++++++++++-- coverage/.last_run.json | 2 +- coverage/.resultset.json | 84 +++++++++++++++++++++++++++------- db/schema.rb | 3 +- spec/pair_selection_spec.rb | 14 ++++-- 5 files changed, 109 insertions(+), 28 deletions(-) diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index 1683067..f214cce 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -1,18 +1,42 @@ module PairingsHelper # Return an array of potential partners in descending order of attractiveness - def pair_me(primary_user, cohort, cohort_pair_history = []) + def pair_me(primary_user) # Filter the available partners from the current cohort # Next version should filter users already paired for today in pair history - cohort_users = User.where(cohort_id: cohort.id).find_each.to_a - available_users = cohort_users.reject do |user| - user == primary_user - end + + available_users = users_in_same_cohort_as(primary_user) + available_users = remove_user(available_users, primary_user) return available_users.shuffle end + def save_entire_pair(users=[]) + users.each do |user| + pair_id = Pairing.maximum(:pair_id).to_i+1 + Pairing.create(pair_id: pair_id, user_id: user.id, cohort_id: user.cohort_id) + end + end + + def users_in_same_cohort_as(user) + return User.where(cohort_id: user.cohort_id).find_each.to_a + end + + def remove_user(user_list, reject_user=nil) + return user_list.reject { |user| user == reject_user } + end + + def users_in_cohort(cohort) + return User.where(cohort_id: cohort.id).find_each.to_a + end + + def unpaired_users_today(cohort) + return users_in_cohort(cohort).reject do |user| + Pairing.where(user_id: user.id, created_at: Date.today).first != nil + end + end + # def assign_pairs(cohort_name) # # this is a method used elsewhere # # odd number should return a final pair of one person diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3cb5e70..46999e6 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 100.0 + "covered_percent": 95.04 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 02c6a3e..6bb682f 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -216,6 +216,11 @@ null, null ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/omniauth.rb": [ + 1, + 1, + null + ], "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/initializers/session_store.rb": [ null, null, @@ -238,6 +243,10 @@ null ], "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/config/routes.rb": [ + 1, + 1, + 1, + 1, 1, 1, null, @@ -307,12 +316,36 @@ 1, null, null, - 2, - 2, - 22, null, + 8, + 8, + null, + 8, + null, + null, + null, + 1, + 5, + 10, + 10, null, - 2, + null, + null, + 1, + 8, + null, + null, + 1, + 150, + null, + null, + 1, + 6, + null, + null, + 1, + 6, + 120, null, null, null, @@ -323,6 +356,10 @@ null, null ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/helpers/sessions_helper.rb": [ + 1, + null + ], "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/helpers/users_helper.rb": [ 1, null @@ -335,29 +372,26 @@ 1, null, 1, - 2, - 2, - 24, + 3, + 3, + 45, null, null, 1, 1, - null, - null, - null, + 5, + 5, null, null, null, 1, 1, - null, - null, 1, 1, null, null, - null, - null, + 1, + 1, 1, 1, 20, @@ -365,7 +399,9 @@ null, null, 1, - null, + 1, + 1, + 1, null, null, null, @@ -383,14 +419,28 @@ ], "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/models/user.rb": [ 1, - null, 1, 1, 1, null, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + null, + null, + null + ], + "/Users/makerslaptop21/Google Drive/MAcademy/pairmiscuous/app/models/pairing.rb": [ + 1, + null, + 1, null ] }, - "timestamp": 1435316372 + "timestamp": 1435322088 } } diff --git a/db/schema.rb b/db/schema.rb index 6da1425..c7e973d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,7 +13,6 @@ ActiveRecord::Schema.define(version: 20150626075904) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -41,10 +40,10 @@ t.string "slack_username" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "cohort_id" t.string "provider" t.string "uid" t.string "name" - t.integer "cohort_id" end add_index "users", ["cohort_id"], name: "index_users_on_cohort_id", using: :btree diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index ae21435..1ba8737 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -10,15 +10,22 @@ def create_test_cohort(cohort_size) cohort_size.times {@user << @cohort.users.create()} end + def create_pair_history(cohort,number_pairs,date=Date.today) + number_pairs.times do + user = unpaired_users_today(cohort)[0] + save_entire_pair([user,pair_me(user)[0]]) + end + end + it 'should return a cohort pair partner' do create_test_cohort(2) - result = pair_me(@user[0],@cohort) + result = pair_me(@user[0]) expect(result).to eq([@user[1]]) end it 'should return all cohort partners excluding the user being matched' do create_test_cohort(20) - result = pair_me(@user[0],@cohort).sort + result = pair_me(@user[0]).sort expect(result.length).to eq(19) @user[1..19].each { |use| expect(result).to include(use) } expect(result).not_to include(@user[0]) @@ -26,7 +33,8 @@ def create_test_cohort(cohort_size) it 'should return all cohort partners excluding those already paired today' do create_test_cohort(20) - + create_pair_history(@cohort,5) + expect(pair_me(unpaired_users_today(@cohort)[0]).length).to eq 9 end end From b41c86cc2cab1fac806471d9c27c8bb80044bf37 Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 13:59:33 +0100 Subject: [PATCH 08/16] passing test to show unpaired people as potential partners --- app/helpers/pairings_helper.rb | 9 +++++++-- coverage/.last_run.json | 2 +- coverage/.resultset.json | 17 ++++++++++++----- spec/pair_selection_spec.rb | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index f214cce..994ce9f 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -5,9 +5,10 @@ def pair_me(primary_user) # Filter the available partners from the current cohort # Next version should filter users already paired for today in pair history - available_users = users_in_same_cohort_as(primary_user) + available_users = unpaired_users_today(cohort_of_user(primary_user)) available_users = remove_user(available_users, primary_user) + return available_users.shuffle end @@ -23,6 +24,10 @@ def users_in_same_cohort_as(user) return User.where(cohort_id: user.cohort_id).find_each.to_a end + def cohort_of_user(user) + return Cohort.where(id: user.cohort_id).first + end + def remove_user(user_list, reject_user=nil) return user_list.reject { |user| user == reject_user } end @@ -33,7 +38,7 @@ def users_in_cohort(cohort) def unpaired_users_today(cohort) return users_in_cohort(cohort).reject do |user| - Pairing.where(user_id: user.id, created_at: Date.today).first != nil + Pairing.where("created_at >= ? AND user_id = ?", Time.zone.now.beginning_of_day, user.id).first != nil end end diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 46999e6..9b30592 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 95.04 + "covered_percent": 94.35 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 6bb682f..8990b20 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -320,6 +320,7 @@ 8, 8, null, + null, 8, null, null, @@ -332,20 +333,24 @@ null, null, 1, + 0, + null, + null, + 1, 8, null, null, 1, - 150, + 120, null, null, 1, - 6, + 14, null, null, 1, - 6, - 120, + 14, + 262, null, null, null, @@ -368,6 +373,7 @@ 1, 1, 1, + 1, null, 1, null, @@ -401,6 +407,7 @@ 1, 1, 1, + null, 1, null, null, @@ -441,6 +448,6 @@ null ] }, - "timestamp": 1435322088 + "timestamp": 1435323434 } } diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index 1ba8737..69a3ce3 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -1,6 +1,7 @@ require 'rails_helper' require './app/helpers/pairings_helper' include PairingsHelper +require 'byebug' describe 'Create a pair' do From a76b4872be33f37ceeedf1c274f52689277f131e Mon Sep 17 00:00:00 2001 From: Mollie Stephenson Date: Fri, 26 Jun 2015 14:00:11 +0100 Subject: [PATCH 09/16] all tests passing --- app/controllers/users_controller.rb | 5 + app/views/users/index.html.erb | 16 +- app/views/users/matrix.html.erb | 4 + config/routes.rb | 1 + coverage/.last_run.json | 5 + coverage/.resultset.json | 471 ++++++++++++++++++++++++++++ coverage/.resultset.json.lock | 0 db/schema.rb | 7 +- spec/feature/user_feature_spec.rb | 9 +- 9 files changed, 503 insertions(+), 15 deletions(-) create mode 100644 app/views/users/matrix.html.erb create mode 100644 coverage/.last_run.json create mode 100644 coverage/.resultset.json create mode 100644 coverage/.resultset.json.lock diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 89e2ec5..f68cd71 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -62,6 +62,11 @@ def destroy end end + def matrix + @current_user = User.last.username + @next_to_pair = User.first.username + end + private # Use callbacks to share common setup or constraints between actions. def set_user diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index d39c96b..585ce23 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -5,17 +5,17 @@ - - - - - - + + + + + + <%= "You are paired with #{@next_pair}" %> - + <%= link_to 'Accept', matrix_path %> <% @users.each do |user| %> @@ -31,3 +31,5 @@
UsernameFull nameProfile pictureSlack username
UsernameFull nameProfile pictureSlack username
<%= user.username %>

+ +<%= link_to 'New User', new_user_path %> diff --git a/app/views/users/matrix.html.erb b/app/views/users/matrix.html.erb new file mode 100644 index 0000000..320bb8f --- /dev/null +++ b/app/views/users/matrix.html.erb @@ -0,0 +1,4 @@ +
+<%= "#{@current_user} and #{@next_to_pair}" %> +
+<%= "Congratulations on pairing." %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 08f4b7f..fa2e5ef 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ get "/login" => 'sessions#new' get "/auth/:provider/callback" => "sessions#create" get "/signout" => "sessions#destroy", :as => :signout + get "/matrix" => 'users#matrix' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/coverage/.last_run.json b/coverage/.last_run.json new file mode 100644 index 0000000..fd05721 --- /dev/null +++ b/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "covered_percent": 86.76 + } +} diff --git a/coverage/.resultset.json b/coverage/.resultset.json new file mode 100644 index 0000000..8ed2fe7 --- /dev/null +++ b/coverage/.resultset.json @@ -0,0 +1,471 @@ +{ + "RSpec": { + "coverage": { + "/Users/mollie/Makers/pairmiscuous/spec/dummy_test_spec.rb": [ + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/spec/rails_helper.rb": [ + null, + 1, + 1, + null, + 1, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + 1, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/environment.rb": [ + null, + 1, + null, + null, + 1 + ], + "/Users/mollie/Makers/pairmiscuous/config/application.rb": [ + 1, + null, + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + null, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + 1, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/boot.rb": [ + 1, + null, + 1 + ], + "/Users/mollie/Makers/pairmiscuous/config/environments/test.rb": [ + 1, + null, + null, + null, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null, + 1, + null, + null, + 1, + null, + null, + 1, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/assets.rb": [ + null, + null, + null, + 1, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/backtrace_silencers.rb": [ + null, + null, + null, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/cookies_serializer.rb": [ + null, + null, + 1 + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ + null, + null, + null, + 1 + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/inflections.rb": [ + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/mime_types.rb": [ + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/omniauth.rb": [ + 1, + 1, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/session_store.rb": [ + null, + null, + 1 + ], + "/Users/mollie/Makers/pairmiscuous/config/initializers/wrap_parameters.rb": [ + null, + null, + null, + null, + null, + null, + 1, + 1, + null, + null, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/config/routes.rb": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/helpers/application_helper.rb": [ + 1, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/helpers/sessions_helper.rb": [ + 1, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/helpers/users_helper.rb": [ + 1, + null + ], + "/Users/mollie/Makers/pairmiscuous/spec/feature/user_feature_spec.rb": [ + 1, + null, + null, + 1, + null, + 1, + 2, + 2, + 2, + 2, + null, + null, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + 1, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/models/user.rb": [ + 1, + 1, + 1, + 1, + null, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + null, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/controllers/users_controller.rb": [ + 1, + 1, + null, + null, + null, + 1, + 2, + 2, + null, + null, + null, + null, + 1, + null, + null, + null, + 1, + 1, + null, + null, + null, + 1, + null, + null, + null, + null, + 1, + 1, + null, + 1, + 1, + 2, + 1, + null, + 0, + 0, + null, + null, + null, + null, + null, + null, + 1, + 0, + 0, + 0, + 0, + null, + 0, + 0, + null, + null, + null, + null, + null, + null, + 1, + 0, + 0, + 0, + 0, + null, + null, + null, + 1, + 1, + 1, + null, + null, + 1, + null, + 1, + 1, + null, + null, + null, + 1, + 1, + null, + null + ], + "/Users/mollie/Makers/pairmiscuous/app/controllers/application_controller.rb": [ + 1, + null, + null, + 1, + 1, + null, + 1, + null, + 1, + 5, + null, + null + ] + }, + "timestamp": 1435318653 + } +} diff --git a/coverage/.resultset.json.lock b/coverage/.resultset.json.lock new file mode 100644 index 0000000..e69de29 diff --git a/db/schema.rb b/db/schema.rb index b58da69..c7e973d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,8 @@ # # It's strongly recommended that you check this file into your version control system. - ActiveRecord::Schema.define(version: 20150626075904) do - # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -42,13 +40,10 @@ t.string "slack_username" t.datetime "created_at", null: false t.datetime "updated_at", null: false -<<<<<<< HEAD -======= + t.integer "cohort_id" t.string "provider" t.string "uid" t.string "name" ->>>>>>> 52d90f5afca7da467e52f99b125f145ad8410259 - t.integer "cohort_id" end add_index "users", ["cohort_id"], name: "index_users_on_cohort_id", using: :btree diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb index 9bf4a87..5be7137 100644 --- a/spec/feature/user_feature_spec.rb +++ b/spec/feature/user_feature_spec.rb @@ -18,11 +18,16 @@ scenario 'accepting a pair' do sign_up('Rocco', 'rocco') click_link('Back') - click_button('Accept') - expect(page).to have_content('Rocco and Chidu') + click_link('Accept') + expect(page).to have_content('Rocco and Molly') expect(page).to have_content('Congratulations on pairing.') end + scenario 'no pairs available' do + sign_up('Rocco', 'rocco') + click_link('Back') + + def sign_up(username, name) visit new_user_path fill_in('Full name', with: name) From 497268ee4607243d2b4467cc68037d42abd59567 Mon Sep 17 00:00:00 2001 From: Mollie Stephenson Date: Fri, 26 Jun 2015 14:17:10 +0100 Subject: [PATCH 10/16] Adds accepting a pair --- coverage/.last_run.json | 2 +- coverage/.resultset.json | 92 ++++++------------------------- spec/feature/user_feature_spec.rb | 10 +++- 3 files changed, 27 insertions(+), 77 deletions(-) diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 3cb5e70..edf57af 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 100.0 + "covered_percent": 82.76 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 46c7bf9..d3df6ce 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -1,11 +1,7 @@ { "RSpec": { "coverage": { -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/spec/dummy_test_spec.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/spec/dummy_test_spec.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e 1, null, 1, @@ -16,11 +12,7 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/spec/rails_helper.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/spec/rails_helper.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, 1, 1, @@ -74,22 +66,14 @@ 1, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/environment.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/environment.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, 1, null, null, 1 ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/application.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/application.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e 1, null, 1, @@ -126,20 +110,12 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/boot.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/boot.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e 1, null, 1 ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/environments/test.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/environments/test.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e 1, null, null, @@ -183,11 +159,7 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/assets.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/assets.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, @@ -200,11 +172,7 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/backtrace_silencers.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/backtrace_silencers.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, @@ -213,30 +181,18 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/cookies_serializer.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/cookies_serializer.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, 1 ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, 1 ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/inflections.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/inflections.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, @@ -254,35 +210,23 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/mime_types.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/mime_types.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/omniauth.rb": [ 1, 1, null ], "/Users/mollie/Makers/pairmiscuous/config/initializers/session_store.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/session_store.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, 1 ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/initializers/wrap_parameters.rb": [ -======= - "/Users/rocco/makers/week9/pairmiscuous/config/initializers/wrap_parameters.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e null, null, null, @@ -298,16 +242,14 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/config/routes.rb": [ 1, + null, + null, 1, 1, 1, 1, -======= - "/Users/rocco/makers/week9/pairmiscuous/config/routes.rb": [ ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e 1, 1, null, @@ -366,7 +308,6 @@ null, null ], -<<<<<<< HEAD "/Users/mollie/Makers/pairmiscuous/app/helpers/application_helper.rb": [ 1, null @@ -379,6 +320,10 @@ 1, null ], + "/Users/mollie/Makers/pairmiscuous/app/helpers/welcome_helper.rb": [ + 1, + null + ], "/Users/mollie/Makers/pairmiscuous/spec/feature/user_feature_spec.rb": [ 1, null, @@ -406,6 +351,17 @@ null, null, 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + null, + null, + null, + 1, 1, 1, 1, @@ -527,18 +483,6 @@ null ] }, - "timestamp": 1435318653 -======= - "/Users/rocco/makers/week9/pairmiscuous/app/helpers/application_helper.rb": [ - 1, - null - ], - "/Users/rocco/makers/week9/pairmiscuous/app/helpers/users_helper.rb": [ - 1, - null - ] - }, - "timestamp": 1435306949 ->>>>>>> 5e72e26986182bce31a020cb50885c7f1ddedf3e + "timestamp": 1435324589 } } diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb index 5be7137..fa3934c 100644 --- a/spec/feature/user_feature_spec.rb +++ b/spec/feature/user_feature_spec.rb @@ -5,7 +5,7 @@ before(:each) do User.create(username: "Molly") - User.create(username: "Rocco") + User.create(username: "Daryl") User.create(username: "Tim") User.create(username: 'Chidu') end @@ -23,9 +23,15 @@ expect(page).to have_content('Congratulations on pairing.') end - scenario 'no pairs available' do + xscenario 'no pairs available' do + Pairing.create(pair_id: 1, user_id: 1) + Pairing.create(pair_id: 1, user_id: 2) + Pairing.create(pair_id: 2, user_id: 3) + Pairing.create(pair_id: 2, user_id: 4) sign_up('Rocco', 'rocco') click_link('Back') + expect(page).to have_content('Please speak to the coaches to find a pair') + end def sign_up(username, name) From 144a457e88d06cf20c85a7286db045323bf9cc46 Mon Sep 17 00:00:00 2001 From: DanielJohnston Date: Fri, 26 Jun 2015 14:25:41 +0100 Subject: [PATCH 11/16] failing test that creates pairing history and expects on it --- app/helpers/pairings_helper.rb | 1 - coverage/.last_run.json | 2 +- coverage/.resultset.json | 43 +++++++++++++++++++--------------- spec/pair_selection_spec.rb | 11 +++++++-- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index 994ce9f..465c7da 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -8,7 +8,6 @@ def pair_me(primary_user) available_users = unpaired_users_today(cohort_of_user(primary_user)) available_users = remove_user(available_users, primary_user) - return available_users.shuffle end diff --git a/coverage/.last_run.json b/coverage/.last_run.json index 9b30592..f9d8287 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 94.35 + "covered_percent": 94.57 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 8990b20..88953db 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -317,18 +317,17 @@ null, null, null, - 8, - 8, - null, + 3, + 3, null, - 8, + 3, null, null, null, 1, - 5, - 10, - 10, + 18, + 30, + 30, null, null, null, @@ -337,20 +336,20 @@ null, null, 1, - 8, + 3, null, null, 1, - 120, + 35, null, null, 1, - 14, + 22, null, null, 1, - 14, - 262, + 22, + 422, null, null, null, @@ -378,15 +377,14 @@ 1, null, 1, - 3, - 3, - 45, + 4, + 4, + 66, null, null, 1, - 1, - 5, - 5, + 3, + 18, null, null, null, @@ -407,7 +405,14 @@ 1, 1, 1, + 1, null, + null, + 1, + 1, + 1, + 1, + 1, 1, null, null, @@ -448,6 +453,6 @@ null ] }, - "timestamp": 1435323434 + "timestamp": 1435325083 } } diff --git a/spec/pair_selection_spec.rb b/spec/pair_selection_spec.rb index 69a3ce3..bb2b1e6 100644 --- a/spec/pair_selection_spec.rb +++ b/spec/pair_selection_spec.rb @@ -13,8 +13,7 @@ def create_test_cohort(cohort_size) def create_pair_history(cohort,number_pairs,date=Date.today) number_pairs.times do - user = unpaired_users_today(cohort)[0] - save_entire_pair([user,pair_me(user)[0]]) + save_entire_pair(unpaired_users_today(cohort)[0..1]) end end @@ -38,6 +37,14 @@ def create_pair_history(cohort,number_pairs,date=Date.today) expect(pair_me(unpaired_users_today(@cohort)[0]).length).to eq 9 end + it 'should order potential partners by number of times paired' do + create_test_cohort(20) + create_pair_history(@cohort,9,Date.today.days_ago(1)) + create_pair_history(@cohort,4,Date.today.days_ago(2)) + byebug + expect(pair_me(@user[0]).length).to eq 19 + end + end describe 'Pair up a cohort' do From f68ba5a701c32123f195dd8ab02f338312d37c62 Mon Sep 17 00:00:00 2001 From: Mollie Stephenson Date: Fri, 26 Jun 2015 14:31:06 +0100 Subject: [PATCH 12/16] adds replacement pair page --- app/controllers/users_controller.rb | 5 +++ app/views/users/index.html.erb | 1 + app/views/users/replacements.html.erb | 5 +++ config/routes.rb | 1 + coverage/.last_run.json | 2 +- coverage/.resultset.json | 48 +++++++++++++++++---------- spec/feature/user_feature_spec.rb | 8 ++++- 7 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 app/views/users/replacements.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f68cd71..4dc4d8c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -67,6 +67,11 @@ def matrix @next_to_pair = User.first.username end + def replacements + @users = User.all + @users + end + private # Use callbacks to share common setup or constraints between actions. def set_user diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 585ce23..9b07692 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -16,6 +16,7 @@ <%= "You are paired with #{@next_pair}" %> <%= link_to 'Accept', matrix_path %> + <%= link_to 'Reject', replacements_path %> <% @users.each do |user| %> <%= user.username %> diff --git a/app/views/users/replacements.html.erb b/app/views/users/replacements.html.erb new file mode 100644 index 0000000..4dec159 --- /dev/null +++ b/app/views/users/replacements.html.erb @@ -0,0 +1,5 @@ +
    + <% for user in @users %> +
  • <%= user.username %>
  • + <% end %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 11d4aa1..b77dcae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ get "/auth/:provider/callback" => "sessions#create" get "/signout" => "sessions#destroy", :as => :signout get "/matrix" => 'users#matrix' + get "/replacements" => 'users#replacements' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/coverage/.last_run.json b/coverage/.last_run.json index edf57af..7c7b925 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,5 +1,5 @@ { "result": { - "covered_percent": 82.76 + "covered_percent": 83.66 } } diff --git a/coverage/.resultset.json b/coverage/.resultset.json index d3df6ce..5092ec3 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -252,6 +252,7 @@ 1, 1, 1, + 1, null, null, null, @@ -331,10 +332,10 @@ 1, null, 1, - 2, - 2, - 2, - 2, + 3, + 3, + 3, + 3, null, null, 1, @@ -347,6 +348,11 @@ 1, 1, 1, + null, + null, + 1, + 1, + 1, 1, null, null, @@ -362,10 +368,11 @@ null, null, 1, - 1, - 1, - 1, - 1, + 2, + 2, + 2, + 2, + 2, null, null ], @@ -393,8 +400,8 @@ null, null, 1, - 2, - 2, + 3, + 3, null, null, null, @@ -404,7 +411,7 @@ null, null, 1, - 1, + 2, null, null, null, @@ -414,12 +421,12 @@ null, null, 1, - 1, + 2, null, - 1, - 1, 2, - 1, + 2, + 4, + 2, null, 0, 0, @@ -457,14 +464,19 @@ null, null, 1, - null, 1, 1, null, null, + 1, null, 1, + 2, + null, + null, + null, 1, + 2, null, null ], @@ -478,11 +490,11 @@ 1, null, 1, - 5, + 9, null, null ] }, - "timestamp": 1435324589 + "timestamp": 1435325358 } } diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb index fa3934c..7bfdc1f 100644 --- a/spec/feature/user_feature_spec.rb +++ b/spec/feature/user_feature_spec.rb @@ -17,12 +17,17 @@ scenario 'accepting a pair' do sign_up('Rocco', 'rocco') - click_link('Back') click_link('Accept') expect(page).to have_content('Rocco and Molly') expect(page).to have_content('Congratulations on pairing.') end + scenario 'rejecting a pair' do + sign_up('Rocco', 'rocco') + click_link('Reject') + expect(page).to have_content('Daryl Tim Chidu') + end + xscenario 'no pairs available' do Pairing.create(pair_id: 1, user_id: 1) Pairing.create(pair_id: 1, user_id: 2) @@ -39,5 +44,6 @@ def sign_up(username, name) fill_in('Full name', with: name) fill_in('Username', with: username) click_button('Create User') + click_link('Back') end end From 38fb17bf1ab0806f17a3ebffc55c7e75eecd7108 Mon Sep 17 00:00:00 2001 From: Rodney Cullen Date: Fri, 26 Jun 2015 14:55:46 +0100 Subject: [PATCH 13/16] Resoved the glitch in the matrix --- app/controllers/users_controller.rb | 4 ++-- app/views/users/index.html.erb | 2 +- config/routes.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4dc4d8c..df64c96 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -62,14 +62,14 @@ def destroy end end - def matrix + def accept_pair @current_user = User.last.username @next_to_pair = User.first.username + redirect_to matrix_index_path end def replacements @users = User.all - @users end private diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index 9b07692..e5ea608 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -15,7 +15,7 @@ <%= "You are paired with #{@next_pair}" %> - <%= link_to 'Accept', matrix_path %> + <%= link_to 'Accept', accept_pair_path %> <%= link_to 'Reject', replacements_path %> <% @users.each do |user| %> diff --git a/config/routes.rb b/config/routes.rb index 85ce5f9..a2af938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ get "/login" => 'sessions#new' get "/auth/:provider/callback" => "sessions#create" get "/signout" => "sessions#destroy", :as => :signout - get "/matrix" => 'users#matrix' + get "/accept_pair" => 'users#accept_pair' get "/replacements" => 'users#replacements' # The priority is based upon order of creation: first created -> highest priority. From 2718cc26373642f26848684499bbcfd8ade96306 Mon Sep 17 00:00:00 2001 From: Rodney Cullen Date: Fri, 26 Jun 2015 15:02:53 +0100 Subject: [PATCH 14/16] green eggs and ham --- app/controllers/reasons_controller.rb | 4 +++- app/views/users/index.html.erb | 4 +--- app/views/welcome/index.html.erb | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/reasons_controller.rb b/app/controllers/reasons_controller.rb index c21c681..145cd4c 100644 --- a/app/controllers/reasons_controller.rb +++ b/app/controllers/reasons_controller.rb @@ -28,15 +28,17 @@ def create @reason.user_id = current_user.id @reason.pair_id = params[:pair_id] + respond_to do |format| if @reason.save - format.html { redirect_to @reason, notice: 'Reason was successfully created.' } + format.html { redirect_to replacements_path, notice: 'Reason was successfully created.' } format.json { render :show, status: :created, location: @reason } else format.html { render :new } format.json { render json: @reason.errors, status: :unprocessable_entity } end end + end # PATCH/PUT /reasons/1 diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index e5ea608..fc66a32 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -14,9 +14,7 @@ - <%= "You are paired with #{@next_pair}" %> - <%= link_to 'Accept', accept_pair_path %> - <%= link_to 'Reject', replacements_path %> + <% @users.each do |user| %> <%= user.username %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 02af68d..777a08e 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -49,7 +49,10 @@ <% else %> - No (say a reason) + <%= "You are paired with #{@next_pair}" %> + <%= link_to 'Accept', accept_pair_path %> + <%= link_to 'Reject (say reason)', new_reason_path %> + <% end %> From 1c5f8deb295d96cb16ab950ee29ac321c493bb5a Mon Sep 17 00:00:00 2001 From: chidumaga Date: Fri, 26 Jun 2015 16:08:17 +0100 Subject: [PATCH 15/16] adds cohort id to github --- app/controllers/users_controller.rb | 2 +- app/controllers/welcome_controller.rb | 6 + app/helpers/pairings_helper.rb | 3 +- app/models/user.rb | 1 + app/views/users/index.html.erb | 1 + coverage/.last_run.json | 3 +- coverage/.resultset.json | 305 ++++++++++++++++++++++---- spec/feature/user_feature_spec.rb | 4 +- 8 files changed, 277 insertions(+), 48 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index df64c96..eb6e68c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,11 +1,11 @@ class UsersController < ApplicationController + before_action :set_user, only: [:show, :edit, :update, :destroy] # GET /users # GET /users.json def index @users = User.all - @next_pair = User.first.username end # GET /users/1 diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index f9b859b..5902b75 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,4 +1,10 @@ +require 'pairings_helper' + class WelcomeController < ApplicationController + include PairingsHelper + def index + pair_me(current_user) + @next_pair = @list_of_users[0] end end diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index 465c7da..0e7596a 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -4,11 +4,10 @@ module PairingsHelper def pair_me(primary_user) # Filter the available partners from the current cohort # Next version should filter users already paired for today in pair history - available_users = unpaired_users_today(cohort_of_user(primary_user)) available_users = remove_user(available_users, primary_user) - return available_users.shuffle + @list_of_users = available_users.shuffle end diff --git a/app/models/user.rb b/app/models/user.rb index a742acb..d381ea0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,6 +7,7 @@ class User < ActiveRecord::Base def self.create_with_omniauth(auth) create! do |user| user.provider = auth.provider + user.cohort = Cohort.first user.uid = auth.uid user.name = auth.info.name user.profile_picture = auth.info.image diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index fc66a32..3018584 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -15,6 +15,7 @@ + <% @users.each do |user| %> <%= user.username %> diff --git a/coverage/.last_run.json b/coverage/.last_run.json index b7c0689..e2a56c2 100644 --- a/coverage/.last_run.json +++ b/coverage/.last_run.json @@ -1,6 +1,5 @@ { "result": { - "covered_percent": 83.66 + "covered_percent": 72.89 } } - diff --git a/coverage/.resultset.json b/coverage/.resultset.json index 7a50889..ea444a6 100644 --- a/coverage/.resultset.json +++ b/coverage/.resultset.json @@ -1,8 +1,7 @@ -<<<<<<< HEAD { "RSpec": { "coverage": { - "/Users/mollie/Makers/pairmiscuous/spec/dummy_test_spec.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/spec/dummy_test_spec.rb": [ 1, null, 1, @@ -13,7 +12,7 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/spec/rails_helper.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/spec/rails_helper.rb": [ null, 1, 1, @@ -67,14 +66,14 @@ 1, null ], - "/Users/mollie/Makers/pairmiscuous/config/environment.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/environment.rb": [ null, 1, null, null, 1 ], - "/Users/mollie/Makers/pairmiscuous/config/application.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/application.rb": [ 1, null, 1, @@ -111,12 +110,12 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/boot.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/boot.rb": [ 1, null, 1 ], - "/Users/mollie/Makers/pairmiscuous/config/environments/test.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/environments/test.rb": [ 1, null, null, @@ -160,7 +159,7 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/assets.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/assets.rb": [ null, null, null, @@ -173,7 +172,7 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/backtrace_silencers.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/backtrace_silencers.rb": [ null, null, null, @@ -182,18 +181,18 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/cookies_serializer.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/cookies_serializer.rb": [ null, null, 1 ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/filter_parameter_logging.rb": [ null, null, null, 1 ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/inflections.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/inflections.rb": [ null, null, null, @@ -211,23 +210,23 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/mime_types.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/mime_types.rb": [ null, null, null, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/omniauth.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/omniauth.rb": [ 1, 1, null ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/session_store.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/session_store.rb": [ null, null, 1 ], - "/Users/mollie/Makers/pairmiscuous/config/initializers/wrap_parameters.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/initializers/wrap_parameters.rb": [ null, null, null, @@ -243,9 +242,12 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/config/routes.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/config/routes.rb": [ 1, null, + 1, + 1, + 1, null, 1, 1, @@ -253,53 +255,183 @@ 1, 1, 1, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/application_helper.rb": [ + 1, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/matrix_helper.rb": [ 1, null, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, null, null, null, + 0, null, null, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, null, null, null, null, + 0, null, null, null, null, + 1, + 0, + 0, + 0, + 0, + 0, + 0, null, + 0, null, null, + 1, + 0, + 0, null, + 0, + 0, + 0, null, null, + 0, null, null, + 1, + 0, + 0, null, + 0, + 0, + 0, + 0, + 0, null, null, + 0, null, null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/pairings_helper.rb": [ + 1, null, null, + 1, null, null, null, + 3, + 3, null, + 3, null, null, null, + 1, + 18, + 30, + 30, null, null, null, + 1, + 0, + null, null, + 1, + 3, null, null, + 1, + 35, null, null, + 1, + 22, null, null, + 1, + 22, + 422, null, null, null, @@ -310,23 +442,23 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/app/helpers/application_helper.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/reasons_helper.rb": [ 1, null ], - "/Users/mollie/Makers/pairmiscuous/app/helpers/sessions_helper.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/sessions_helper.rb": [ 1, null ], - "/Users/mollie/Makers/pairmiscuous/app/helpers/users_helper.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/users_helper.rb": [ 1, null ], - "/Users/mollie/Makers/pairmiscuous/app/helpers/welcome_helper.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/helpers/welcome_helper.rb": [ 1, null ], - "/Users/mollie/Makers/pairmiscuous/spec/feature/user_feature_spec.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/spec/feature/user_feature_spec.rb": [ 1, null, null, @@ -347,14 +479,14 @@ 1, 1, 1, - 1, - 1, + 0, + 0, null, null, 1, 1, 1, - 1, + 0, null, null, 1, @@ -377,7 +509,81 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/app/models/user.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/spec/pair_selection_spec.rb": [ + 1, + 1, + 1, + 1, + null, + 1, + null, + 1, + 4, + 4, + 66, + null, + null, + 1, + 3, + 18, + null, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + 20, + 1, + null, + null, + 1, + 1, + 1, + 1, + null, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null, + null, + null, + 1, + null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/spec/reason_spec.rb": [ + 1, + null, + 1, + 1, + 1, + 1, + 1, + 1, + null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/models/reason.rb": [ + 1, + 1, + 1, + 1, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/models/user.rb": [ + 1, 1, 1, 1, @@ -394,15 +600,35 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/app/controllers/users_controller.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/controllers/welcome_controller.rb": [ 1, 1, null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/controllers/application_controller.rb": [ + 1, null, null, 1, - 3, - 3, + 1, + null, + 1, + null, + 1, + 10, + null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/controllers/users_controller.rb": [ + 1, + 1, + null, + null, + null, + 1, + 0, + 0, null, null, null, @@ -460,13 +686,13 @@ null, null, 1, - 1, - 1, + 0, + 0, + 0, null, null, 1, - 1, - 1, + 0, null, null, 1, @@ -481,23 +707,20 @@ null, null ], - "/Users/mollie/Makers/pairmiscuous/app/controllers/application_controller.rb": [ + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/models/cohort.rb": [ 1, null, - null, 1, 1, - null, + null + ], + "/Users/makerslaptop66/Desktop/Projects/pairmiscuous/app/models/pairing.rb": [ 1, null, 1, - 9, - null, null ] }, - "timestamp": 1435325358 + "timestamp": 1435328125 } } -======= ->>>>>>> 6fe874ff9f99efa9adde1684bd886e5674ec66bc diff --git a/spec/feature/user_feature_spec.rb b/spec/feature/user_feature_spec.rb index 7bfdc1f..0158e8b 100644 --- a/spec/feature/user_feature_spec.rb +++ b/spec/feature/user_feature_spec.rb @@ -11,7 +11,7 @@ end scenario 'pair is shown' do - visit users_path + visit '/' expect(page).to have_content("You are paired with Molly"); end @@ -44,6 +44,6 @@ def sign_up(username, name) fill_in('Full name', with: name) fill_in('Username', with: username) click_button('Create User') - click_link('Back') + visit '/' end end From c55f0e051d6361af552e7565e32ca9a73b0ec9b1 Mon Sep 17 00:00:00 2001 From: chidumaga Date: Fri, 26 Jun 2015 16:26:08 +0100 Subject: [PATCH 16/16] random pair shows up on homepage --- app/controllers/welcome_controller.rb | 6 ++++-- app/helpers/pairings_helper.rb | 3 ++- app/views/welcome/index.html.erb | 3 ++- db/seeds.rb | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 5902b75..c77db38 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -4,7 +4,9 @@ class WelcomeController < ApplicationController include PairingsHelper def index - pair_me(current_user) - @next_pair = @list_of_users[0] + if current_user + @list = pair_me(current_user) + @next_pair = @list[0] + end end end diff --git a/app/helpers/pairings_helper.rb b/app/helpers/pairings_helper.rb index 0e7596a..2fe1dd7 100644 --- a/app/helpers/pairings_helper.rb +++ b/app/helpers/pairings_helper.rb @@ -5,10 +5,11 @@ def pair_me(primary_user) # Filter the available partners from the current cohort # Next version should filter users already paired for today in pair history available_users = unpaired_users_today(cohort_of_user(primary_user)) + available_users = remove_user(available_users, primary_user) @list_of_users = available_users.shuffle - + @list_of_users end def save_entire_pair(users=[]) diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 777a08e..c8e24eb 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -49,7 +49,8 @@ <% else %> - <%= "You are paired with #{@next_pair}" %> + <%= "You are paired with #{@next_pair.username}" %> + <%= link_to 'Accept', accept_pair_path %> <%= link_to 'Reject (say reason)', new_reason_path %> diff --git a/db/seeds.rb b/db/seeds.rb index 2df74c0..4da1a2f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -42,4 +42,4 @@ def assign_pairs(cohort_name) end end -7.times { assign_pairs('#april2015') } +# 7.times { assign_pairs('#april2015') }