Skip to content

Commit ca63d75

Browse files
committed
Add :github_repositories to User
1 parent bf5b22c commit ca63d75

File tree

6 files changed

+7
-0
lines changed

6 files changed

+7
-0
lines changed

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class User < ActiveRecord::Base
6767
has_many :comments, dependent: :delete_all
6868

6969
has_one :github_profile , class_name: 'Users::Github::Profile', dependent: :destroy
70+
has_many :github_repositories, through: :github_profile , source: :repositories
7071

7172

7273
geocoded_by :location, latitude: :lat, longitude: :lng, country: :country, state_code: :state_name

app/models/users/github/profile.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Users::Github::Profile < ActiveRecord::Base
22
belongs_to :user
33
has_many :followers, class_name: 'Users::Github::Profiles::Follower' , foreign_key: :follower_id , dependent: :delete_all
4+
has_many :repositories, :class_name => 'Users::Github::Repository' , foreign_key: :owner_id
45
end

app/models/users/github/repository.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Users::Github::Repository < ActiveRecord::Base
22
has_many :followers, :class_name => 'Users::Github::Repositories::Follower' , dependent: :delete_all
3+
has_many :contributors, :class_name => 'Users::Github::Repositories::Contributor' , dependent: :delete_all
34
belongs_to :organization, :class_name => 'Users::Github::Organization'
45
belongs_to :owner, :class_name => 'Users::Github::Profile'
56
end

spec/models/user_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'spec_helper'
22

33
RSpec.describe User, :type => :model do
4+
it { is_expected.to have_one :github_profile }
5+
it { is_expected.to have_many :github_repositories }
46
before :each do
57
User.destroy_all
68
end

spec/models/users/github/profile_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
RSpec.describe Users::Github::Profile, :type => :model do
44
it {is_expected.to belong_to :user}
55
it {is_expected.to have_many :followers}
6+
it {is_expected.to have_many :repositories}
67
end

spec/models/users/github/repository_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
RSpec.describe Users::Github::Repository, :type => :model do
44
it { is_expected.to have_many :followers }
5+
it { is_expected.to have_many :contributors }
56
it { is_expected.to belong_to :organization }
67
it { is_expected.to belong_to :owner }
78
end

0 commit comments

Comments
 (0)