Skip to content

Commit 48e79ba

Browse files
committed
Introducing Github profile
1 parent 62f309f commit 48e79ba

28 files changed

+260
-0
lines changed

app/models/user.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class User < ActiveRecord::Base
6868
has_many :likes
6969
has_many :comments, dependent: :delete_all
7070

71+
has_one :github_profile , class_name: 'Users::Github::Profile', dependent: :destroy
72+
73+
7174
geocoded_by :location, latitude: :lat, longitude: :lng, country: :country, state_code: :state_name
7275
after_validation :geocode_location, if: :location_changed? unless Rails.env.test?
7376

app/models/users.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Users
2+
def self.table_name_prefix
3+
'users_'
4+
end
5+
end

app/models/users/github.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Users::Github
2+
def self.table_name_prefix
3+
'users_github_'
4+
end
5+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Users::Github::Organization < ActiveRecord::Base
2+
has_many :followers, class_name: 'Users::Github::Organizations::Follower', dependent: :delete_all
3+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Users::Github::Organizations
2+
def self.table_name_prefix
3+
'users_github_organizations_'
4+
end
5+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Users::Github::Organizations::Follower < ActiveRecord::Base
2+
belongs_to :profile, :class_name => 'Users::Github::Profile'
3+
belongs_to :organization, :class_name => 'Users::Github::Organization'
4+
end

app/models/users/github/profile.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Users::Github::Profile < ActiveRecord::Base
2+
belongs_to :user
3+
has_many :followers, class_name: 'Users::Github::Profiles::Follower' , foreign_key: :follower_id , dependent: :delete_all
4+
end

app/models/users/github/profiles.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Users::Github::Profiles
2+
def self.table_name_prefix
3+
'users_github_profiles_'
4+
end
5+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Users::Github::Profiles::Follower < ActiveRecord::Base
2+
belongs_to :profile, :class_name => 'Users::Github::Profile'
3+
belongs_to :follower, :class_name => 'Users::Github::Profile'
4+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Users::Github::Repositories
2+
def self.table_name_prefix
3+
'users_github_repositories_'
4+
end
5+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Users::Github::Repositories::Contributor < ActiveRecord::Base
2+
belongs_to :profile, class_name: 'Users::Github::Profile'
3+
belongs_to :repository, :class_name => 'Users::Github::Repository'
4+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Users::Github::Repositories::Follower < ActiveRecord::Base
2+
belongs_to :profile, class_name: 'Users::Github::Profile'
3+
belongs_to :repository, :class_name => 'Users::Github::Repository'
4+
end

app/models/users/github/repository.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Users::Github::Repository < ActiveRecord::Base
2+
has_many :followers, :class_name => 'Users::Github::Repositories::Follower' , dependent: :delete_all
3+
belongs_to :organization, :class_name => 'Users::Github::Organization'
4+
belongs_to :owner, :class_name => 'Users::Github::Profile'
5+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class CreateUsersGithubProfiles < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_profiles do |t|
4+
t.string :login
5+
t.string :name
6+
t.string :company
7+
t.string :location
8+
t.integer :github_id, index: true, null: false, unique: true
9+
t.integer :user_id
10+
t.timestamps
11+
end
12+
end
13+
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class CreateUsersGithubRepositories < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_repositories do |t|
4+
t.string :name
5+
t.text :description
6+
t.string :full_name
7+
t.string :homepage
8+
t.boolean :fork , default: false
9+
t.integer :forks_count, default: 0
10+
#TODO remigrate default in rails 4. rails 3 schema dumper is stupid
11+
t.datetime :forks_count_updated_at, default:'NOW()'
12+
t.integer :stargazers_count, default: 0
13+
t.datetime :stargazers_count_updated_at, default:'NOW()'
14+
t.string :language
15+
t.integer :followers_count, default: 0, null: false
16+
t.integer :github_id, index: true, null: false, unique: true
17+
t.integer :owner_id, index: true
18+
t.integer :organization_id, index: true
19+
t.timestamps
20+
21+
end
22+
end
23+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateUsersGithubRepositoriesFollowers < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_repositories_followers, id: false do |t|
4+
t.integer :repository_id, null: false
5+
t.integer :profile_id , null: false
6+
t.timestamps
7+
end
8+
# add_index :users_github_repositories_followers , [:repository_id, :profile_id] , unique: true
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateUsersGithubRepositoriesContributors < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_repositories_contributors, id: false do |t|
4+
t.integer :repository_id, null: false
5+
t.integer :profile_id , null: false
6+
t.timestamps
7+
end
8+
# add_index :users_github_repositories_contributors , [:repository_id, :profile_id] , unique: true
9+
end
10+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateUsersGithubProfilesFollowers < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_profiles_followers, id: false do |t|
4+
t.integer :follower_id, null: false
5+
t.integer :profile_id , null: false
6+
t.timestamps
7+
end
8+
# add_index :users_github_profiles_followers , [:follower_id, :profile_id], unique: true
9+
end
10+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class CreateUsersGithubOrganizations < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_organizations do |t|
4+
t.string :login
5+
t.string :company
6+
t.string :blog
7+
t.string :location
8+
t.string :url
9+
t.integer :github_id
10+
t.datetime :github_created_at
11+
t.datetime :github_updated_at
12+
t.timestamps
13+
end
14+
end
15+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateUsersGithubOrganizationsFollowers < ActiveRecord::Migration
2+
def change
3+
create_table :users_github_organizations_followers, id: false do |t|
4+
t.integer :organization_id, null: false
5+
t.integer :profile_id , null: false
6+
t.timestamps
7+
end
8+
# add_index :users_github_organizations_followers , [:organization_id, :profile_id], unique: true
9+
end
10+
end

db/schema.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,75 @@
515515
add_index "users", ["twitter_id"], :name => "index_users_on_twitter_id", :unique => true
516516
add_index "users", ["username"], :name => "index_users_on_username", :unique => true
517517

518+
create_table "users_github_organizations", :force => true do |t|
519+
t.string "login"
520+
t.string "company"
521+
t.string "blog"
522+
t.string "location"
523+
t.string "url"
524+
t.integer "github_id"
525+
t.datetime "github_created_at"
526+
t.datetime "github_updated_at"
527+
t.datetime "created_at", :null => false
528+
t.datetime "updated_at", :null => false
529+
end
530+
531+
create_table "users_github_organizations_followers", :id => false, :force => true do |t|
532+
t.integer "organization_id", :null => false
533+
t.integer "profile_id", :null => false
534+
t.datetime "created_at", :null => false
535+
t.datetime "updated_at", :null => false
536+
end
537+
538+
create_table "users_github_profiles", :force => true do |t|
539+
t.string "login"
540+
t.string "name"
541+
t.string "company"
542+
t.string "location"
543+
t.integer "github_id", :null => false
544+
t.integer "user_id"
545+
t.datetime "created_at", :null => false
546+
t.datetime "updated_at", :null => false
547+
end
548+
549+
create_table "users_github_profiles_followers", :id => false, :force => true do |t|
550+
t.integer "follower_id", :null => false
551+
t.integer "profile_id", :null => false
552+
t.datetime "created_at", :null => false
553+
t.datetime "updated_at", :null => false
554+
end
555+
556+
create_table "users_github_repositories", :force => true do |t|
557+
t.string "name"
558+
t.text "description"
559+
t.string "full_name"
560+
t.string "homepage"
561+
t.boolean "fork", :default => false
562+
t.integer "forks_count", :default => 0
563+
t.datetime "forks_count_updated_at", :default => '2014-07-18 23:03:00'
564+
t.integer "stargazers_count", :default => 0
565+
t.datetime "stargazers_count_updated_at", :default => '2014-07-18 23:03:00'
566+
t.string "language"
567+
t.integer "followers_count", :default => 0, :null => false
568+
t.integer "github_id", :null => false
569+
t.integer "owner_id"
570+
t.integer "organization_id"
571+
t.datetime "created_at", :null => false
572+
t.datetime "updated_at", :null => false
573+
end
574+
575+
create_table "users_github_repositories_contributors", :id => false, :force => true do |t|
576+
t.integer "repository_id", :null => false
577+
t.integer "profile_id", :null => false
578+
t.datetime "created_at", :null => false
579+
t.datetime "updated_at", :null => false
580+
end
581+
582+
create_table "users_github_repositories_followers", :id => false, :force => true do |t|
583+
t.integer "repository_id", :null => false
584+
t.integer "profile_id", :null => false
585+
t.datetime "created_at", :null => false
586+
t.datetime "updated_at", :null => false
587+
end
588+
518589
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Organization, :type => :model do
4+
it {is_expected.to have_many :followers}
5+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Organizations::Follower, :type => :model do
4+
it {is_expected.to belong_to :profile}
5+
it {is_expected.to belong_to :organization}
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Profile, :type => :model do
4+
it {is_expected.to belong_to :user}
5+
it {is_expected.to have_many :followers}
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Profiles::Follower, :type => :model do
4+
it {is_expected.to belong_to :profile}
5+
it {is_expected.to belong_to :follower}
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Repositories::Contributor, :type => :model do
4+
it {is_expected.to belong_to :profile}
5+
it {is_expected.to belong_to :repository}
6+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Repositories::Follower, :type => :model do
4+
it {is_expected.to belong_to :profile}
5+
it {is_expected.to belong_to :repository}
6+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Users::Github::Repository, :type => :model do
4+
it { is_expected.to have_many :followers }
5+
it { is_expected.to belong_to :organization }
6+
it { is_expected.to belong_to :owner }
7+
end

0 commit comments

Comments
 (0)