Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

a few changes to SqlLoader, continuing to work on team_members view, …

…added view_members_clean to hide devise authentication stuff. *just in case*
  • Loading branch information...
commit 57a27dab4fd4a7334c9aa217b5d07b6fd640a33c 1 parent e2f245a
@dcunited001 authored
View
4 app/models/member.rb
@@ -26,7 +26,7 @@ class Member < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :phone, :birthday, :alias, :address, :address_attributes
accepts_nested_attributes_for :address
- after_create :add_basic_member_role
+ after_create :add_appuser_role
#========================================
# Devise Configuration
@@ -39,7 +39,7 @@ class Member < ActiveRecord::Base
#========================================
# Role Helpers
#========================================
- def add_basic_member_role
+ def add_appuser_role
roles.create(:name => 'appuser')
end
View
5 app/models/team.rb
@@ -18,7 +18,7 @@ def creator= member
TeamMember.where(:team_id => self.id, :member_requesting_id => creator.id, :member_requested_id => creator.id).first.delete
creator.remove_role(:teamcreator, self)
else
- original_creator_id = member.id
+ self.original_creator_id = member.id
end
#create a special TeamRequest record for the new creator and assign roles
@@ -27,7 +27,8 @@ def creator= member
:member_requesting_id => member.id,
:member_requested_id => member.id,
:approved => true,
- :active => true)
+ :active => true,
+ :incoming => false)
member.assign_role(:teamcreator, self)
#finally, if all is well in transaction-land,
View
8 app/models/team_request.rb
@@ -6,12 +6,4 @@ class TeamRequest < ActiveRecord::Base
#scope :recd
#scope :sent
-
- after_create :set_original_creator
-
- private
-
- def set_original_creator
- original_creator_id = team.original_creator_id
- end
end
View
2  db/migrate/20110711102208_create_team_requests.rb
@@ -2,9 +2,9 @@ class CreateTeamRequests < ActiveRecord::Migration
def self.up
create_table "team_requests", :force => true do |t|
t.integer "team_id"
- t.integer "original_creator_id"
t.integer "member_requesting_id"
t.integer "member_requested_id"
+ t.boolean "incoming", :default => true
t.boolean "team_request", :default => true
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
View
2  db/schema.rb
@@ -143,9 +143,9 @@
create_table "team_requests", :force => true do |t|
t.integer "team_id"
- t.integer "original_creator_id"
t.integer "member_requesting_id"
t.integer "member_requested_id"
+ t.boolean "incoming", :default => true
t.boolean "team_request", :default => true
t.boolean "approved", :default => false
t.boolean "rejected", :default => false
View
8 db/seeds.rb
@@ -130,6 +130,7 @@
#breaksk8
beef_jerky = Factory(:member, :alias => 'beef_jerky')
shannon = Factory(:member, :alias => 'breaksk8master')
+curly = Factory(:member, :alias => 'curly')
#phase_two
dennis_gk = Factory(:member, :alias => 'dennis-gk')
@@ -138,20 +139,23 @@
#authentic_freaks
quinton = Factory(:member, :alias => 'quinton')
james = Factory(:member, :alias => 'anaconda')
+brandon = Factory(:member, :alias => 'bb_sk8r')
puts 'Creating Some Teams'
jammers_va = Factory(:team, :name => 'Jammers VA', :creator => dcunited)
Factory(:team_member, :team => jammers_va, :member_requesting => dcunited, :member_requested => xm_jester_mx)
-Factory(:team_member, :team => jammers_va, :member_requesting => dcunited, :member_requested => cooper)
+Factory(:team_member_from, :team => jammers_va, :member_requesting => cooper, :member_requested => dcunited)
breaksk8 = Factory(:team, :name => 'Breaksk8', :creator => shannon)
-Factory(:team_member, :team => breaksk8, :member_requesting => shannon, :member_requested => beef_jerky)
+Factory(:team_member_from, :team => breaksk8, :member_requesting => beef_jerky, :member_requested => shannon)
+Factory(:team_member, :team => breaksk8, :member_requesting => shannon, :member_requested => curly)
phase_two = Factory(:team, :name => 'Phase Two', :creator => dennis_gk)
Factory(:team_member, :team => phase_two, :member_requesting => dennis_gk, :member_requested => ballentine)
authentic = Factory(:team, :name => 'Authentic Freaks', :creator => james)
Factory(:team_member, :team => authentic, :member_requesting => james, :member_requested => quinton)
+Factory(:team_member_from, :team => authentic, :member_requesting => brandon, :member_requested => james)
# ======================================
# TEAM MEMBERS
View
28 db/sql_loader.rb
@@ -40,18 +40,26 @@ class SqlLoaderBase
SQL_LOADER_ROOT = File.join(Rails.root, 'db/sql_loader')
Dir[File.join(SQL_LOADER_ROOT, "*.rb")].each {|rb| require rb }
+ #order is important here,
+ # as their objects will be created in order
+ # and dropped in reverse order
+ def self.all_classes
+ #more advanced load options will be added later
+
+ [Member,
+ Friend,
+ TeamMate,
+ TeamMember,
+ TeamCaptain]
+ end
+
def self.create_all
- [Friend,
- TeamMate,
- TeamMember,
- TeamCaptain].each {|klass| klass.create}
+ # i finally feel cool enough to spell class with a "k"
+ all_classes.each {|klass| klass.create}
end
def self.drop_all
- [Friend,
- TeamMate,
- TeamMember,
- TeamCaptain].each {|klass| klass.drop}
+ all_classes.reverse.each {|klass| klass.drop}
end
def self.relative_name
@@ -121,7 +129,7 @@ def self.create_error_output errors
out += "#{CREATE_ERRORS}\n"
errors.each {|e| out += "\n\n#{CREATE_DELIMETER}\n#{e}\n" }
- puts out if @@debug
+ puts out
raise "SqlLoader Exception"
else
out += NO_CREATE_ERRORS
@@ -136,7 +144,7 @@ def self.drop_error_output errors
out += "#{DROP_ERRORS}\n"
errors.each {|e| out += "\n\n#{DROP_DELIMETER}\n#{e}\n" }
- puts out if @@debug
+ puts out
raise "SqlLoader Exception"
else
out += NO_DROP_ERRORS
View
5 db/sql_loader/member.rb
@@ -0,0 +1,5 @@
+module SqlLoader
+ class Member < SqlLoaderBase
+
+ end
+end
View
29 db/sql_loader/member/view_members_clean.sql
@@ -0,0 +1,29 @@
+CREATE VIEW view_members_clean AS
+
+SELECT
+ id,
+ email,
+ sign_in_count,
+ current_sign_in_at,
+ last_sign_in_at,
+ current_sign_in_ip,
+ last_sign_in_ip,
+ created_at,
+ updated_at,
+ alias,
+ first_name,
+ last_name,
+ rink_id,
+ birthday,
+ phone,
+ verified,
+ original_verified_date,
+ last_verified_date,
+ current_member,
+ original_membership_date,
+ last_membership_date,
+ renewal_months,
+ pro_skater,
+ suspended,
+ suspended_until
+FROM members
View
53 db/sql_loader/team_member/view_team_members.sql
@@ -1,4 +1,3 @@
-CREATE VIEW view_team_members AS
-- i'll remove these comments as I determine my strategy here.
@@ -18,6 +17,8 @@ CREATE VIEW view_team_members AS
-- that's going to open me up to some particularly nasty bugs
-- which would probably silently ruin the integrity of my data
+-- changing team_requests table to use an "incoming" field to determine the team_member
+
-- =============================================================================
--goal of this view:
@@ -33,28 +34,46 @@ CREATE VIEW view_team_members AS
-- using string substitution in the commented query below
-- =============================================================================
+CREATE VIEW view_team_members AS
+SELECT t.id as team_id, tm.id as team_request_id, team_mems.*
+FROM teams t
-SELECT t.id as team_id, tm.id as team_request_id, this_member.id as member_id, team_mems.*
-FROM members this_member
-
---join to get the member's team
-INNER JOIN team_requests active_tm
- ON (this_member.id = active_tm.member_requesting_id
- OR this_member.id = active_tm.member_requested_id)
- AND active_tm.active = true
-INNER JOIN teams t
- ON active_tm.team_id = t.id
-
---join back to team_requests
--- to get the current team members
INNER JOIN team_requests tm
ON t.id = tm.team_id
AND tm.active = true
+
INNER JOIN members team_mems
- ON (team_mems.id = tm.member_requesting_id and t.creator_id = this_member.id)
- OR (team_mems.id = tm.member_requested_id and t.creator_id != this_member.id)
-WHERE team_mems.id != this_member.id
+ --if it's an incoming request, the member requesting is the team member
+ --otherwise the member requested is the team member
+ ON (team_mems.id = tm.member_requesting_id AND tm.incoming = true)
+ OR (team_mems.id = tm.member_requested_id AND tm.incoming = false)
+
+
+
+
+
+
+-- SELECT t.id as team_id, tm.id as team_request_id, this_member.id as member_id, team_mems.*
+-- FROM members this_member
+--
+-- --join to get the member's team
+-- INNER JOIN team_requests active_tm
+-- ON (this_member.id = active_tm.member_requesting_id
+-- OR this_member.id = active_tm.member_requested_id)
+-- AND active_tm.active = true
+-- INNER JOIN teams t
+-- ON active_tm.team_id = t.id
+--
+-- --join back to team_requests
+-- -- to get the current team members
+-- INNER JOIN team_requests tm
+-- ON t.id = tm.team_id
+-- AND tm.active = true
+-- INNER JOIN members team_mems
+-- ON (team_mems.id = tm.member_requesting_id and t.creator_id = this_member.id)
+-- OR (team_mems.id = tm.member_requested_id and t.creator_id != this_member.id)
+-- WHERE team_mems.id != this_member.id
View
6 spec/factories/members.rb
@@ -9,13 +9,9 @@
member.birthday random_date(1985, 10)
member.phone random_phone
- member. rink_id -1
+ member.rink_id -1
member.address {|m| m.association(:address)}
-
- member.after_create do |m|
- m.assign_role(:appuser)
- end
end
Factory.define(:admin, :parent => :member) do |member|
View
9 spec/factories/team_requests.rb
@@ -2,6 +2,11 @@
team_request.association :team
team_request.association :member_requesting
team_request.association :member_requested
+ team_request.incoming false
+end
+
+Factory.define(:team_request_from, :parent => :team_request) do |team_request|
+ team_request.incoming true
end
Factory.define(:team_member, :parent => :team_request) do |team_request|
@@ -9,6 +14,10 @@
team_request.active true
end
+Factory.define(:team_member_from, :parent => :team_member) do |team_request|
+ team_request.incoming true
+end
+
Factory.define(:rejected_team_request, :parent => :team_request) do |team_request|
team_request.rejected true
end
Please sign in to comment.
Something went wrong with that request. Please try again.