From 54f8d4f93385b8806df1d69b88c236d30070924d Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 20 Jul 2014 00:07:39 +0200 Subject: [PATCH] failing test for #68 --- test/HasManyThroughTest.php | 37 +++++++++++++++++++++++++++++++++++++ test/RelationshipTest.php | 8 ++++++++ 2 files changed, 45 insertions(+) diff --git a/test/HasManyThroughTest.php b/test/HasManyThroughTest.php index 3e9982526..1dcbdf3c3 100644 --- a/test/HasManyThroughTest.php +++ b/test/HasManyThroughTest.php @@ -55,4 +55,41 @@ public function test_gh107_has_many_though_include_eager_with_namespace() $this->assert_equals(1, $user->id); $this->assert_equals(1, $user->newsletters[0]->id); } + + public function test_gh68_has_many_through_with_missing_associations() + { + Property::$has_many = array( + array('amenities', 'through' => 'property_amenities') + ); + Amenity::$has_many = array( + array('properties', 'through' => 'property_amenities') + ); + + $property = Property::find('first'); + try{ + $property->amenities; + $this->fail('Should trigger exception'); + }catch(ActiveRecord\HasManyThroughAssociationException $e){ + $this->assertEquals('Could not find the association property_amenities in model Property', $e->getMessage()); + } + } + + public function test_gh68_has_many_through_with_missing_association() + { + Property::$has_many = array( + 'property_amenities', + array('amenities', 'through' => 'property_amenities') + ); + Amenity::$has_many = array( + array('properties', 'through' => 'property_amenities') + ); + + $amenity = Amenity::find('first'); + try{ + $amenity->properties; + $this->fail('Should trigger exception'); + }catch(ActiveRecord\HasManyThroughAssociationException $e){ + $this->assertEquals('Could not find the association property_amenities in model Amenity', $e->getMessage()); + } + } } diff --git a/test/RelationshipTest.php b/test/RelationshipTest.php index 9837f67aa..6adce031d 100644 --- a/test/RelationshipTest.php +++ b/test/RelationshipTest.php @@ -341,6 +341,14 @@ public function test_has_many_through() public function test_gh27_has_many_through_with_explicit_keys() { + Property::$has_many = array( + 'property_amenities', + array('amenities', 'through' => 'property_amenities') + ); + Amenity::$has_many = array( + 'property_amenities' + ); + $property = Property::first(); $this->assert_equals(1, $property->amenities[0]->amenity_id);