Add test_has_one_through_has_one_through_with_belongs_to_source_reflection
This commit is contained in:
parent
25acd19da5
commit
002985fb66
@ -26,6 +26,7 @@
|
||||
require 'models/organization'
|
||||
require 'models/category'
|
||||
require 'models/categorization'
|
||||
require 'models/membership'
|
||||
|
||||
# NOTE: Some of these tests might not really test "nested" HMT associations, as opposed to ones which
|
||||
# are just one level deep. But it's all the same thing really, as the "nested" code is being
|
||||
@ -36,7 +37,7 @@ class NestedHasManyThroughAssociationsTest < ActiveRecord::TestCase
|
||||
fixtures :authors, :books, :posts, :subscriptions, :subscribers, :tags, :taggings,
|
||||
:people, :readers, :references, :jobs, :ratings, :comments, :members, :member_details,
|
||||
:member_types, :sponsors, :clubs, :organizations, :categories, :categories_posts,
|
||||
:categorizations
|
||||
:categorizations, :memberships
|
||||
|
||||
# Through associations can either use the has_many or has_one macros.
|
||||
#
|
||||
@ -241,9 +242,19 @@ def test_has_one_through_has_one_with_has_one_through_source_reflection
|
||||
assert_equal member_types(:founding), members.first.nested_member_type
|
||||
end
|
||||
|
||||
# TODO: has_one through
|
||||
# has_one through
|
||||
# Source: belongs_to
|
||||
# Through: has_one through
|
||||
def test_has_one_through_has_one_through_with_belongs_to_source_reflection
|
||||
assert_equal categories(:general), members(:groucho).club_category
|
||||
|
||||
members = Member.joins(:club_category).where('categories.id' => categories(:technology).id)
|
||||
assert_equal [members(:blarpy_winkup)], members
|
||||
|
||||
# TODO: Make this work
|
||||
# members = Member.includes(:club_category)
|
||||
# assert_equal categories(:general), members.first.club_category
|
||||
end
|
||||
|
||||
def test_distinct_has_many_through_a_has_many_through_association_on_source_reflection
|
||||
author = authors(:david)
|
||||
|
4
activerecord/test/fixtures/clubs.yml
vendored
4
activerecord/test/fixtures/clubs.yml
vendored
@ -1,6 +1,8 @@
|
||||
boring_club:
|
||||
name: Banana appreciation society
|
||||
category_id: 1
|
||||
moustache_club:
|
||||
name: Moustache and Eyebrow Fancier Club
|
||||
crazy_club:
|
||||
name: Skull and bones
|
||||
name: Skull and bones
|
||||
category_id: 2
|
||||
|
3
activerecord/test/fixtures/members.yml
vendored
3
activerecord/test/fixtures/members.yml
vendored
@ -6,3 +6,6 @@ some_other_guy:
|
||||
id: 2
|
||||
name: Englebert Humperdink
|
||||
member_type_id: 2
|
||||
blarpy_winkup:
|
||||
id: 3
|
||||
name: Blarpy Winkup
|
||||
|
7
activerecord/test/fixtures/memberships.yml
vendored
7
activerecord/test/fixtures/memberships.yml
vendored
@ -18,3 +18,10 @@ other_guys_membership:
|
||||
member_id: 2
|
||||
favourite: false
|
||||
type: CurrentMembership
|
||||
|
||||
blarpy_winkup_crazy_club:
|
||||
joined_on: <%= 4.weeks.ago.to_s(:db) %>
|
||||
club: crazy_club
|
||||
member_id: 3
|
||||
favourite: false
|
||||
type: CurrentMembership
|
||||
|
@ -4,10 +4,11 @@ class Club < ActiveRecord::Base
|
||||
has_many :current_memberships
|
||||
has_one :sponsor
|
||||
has_one :sponsored_member, :through => :sponsor, :source => :sponsorable, :source_type => "Member"
|
||||
belongs_to :category
|
||||
|
||||
private
|
||||
|
||||
def private_method
|
||||
"I'm sorry sir, this is a *private* club, not a *pirate* club"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,4 +18,6 @@ class Member < ActiveRecord::Base
|
||||
|
||||
has_many :organization_member_details, :through => :member_detail
|
||||
has_many :organization_member_details_2, :through => :organization, :source => :member_details
|
||||
|
||||
has_one :club_category, :through => :club, :source => :category
|
||||
end
|
||||
|
@ -113,6 +113,7 @@ def create_table(*args, &block)
|
||||
|
||||
create_table :clubs, :force => true do |t|
|
||||
t.string :name
|
||||
t.integer :category_id
|
||||
end
|
||||
|
||||
create_table :collections, :force => true do |t|
|
||||
|
Loading…
Reference in New Issue
Block a user