|
137 | 137 | let(:user_with_included_data_after_create) { Foo::User.create } |
138 | 138 | let(:user_with_included_data_after_save_existing) { Foo::User.save_existing(5, :name => "Clancy Brown") } |
139 | 139 | let(:user_with_included_data_after_destroy) { Foo::User.new(:id => 5).destroy } |
| 140 | + let(:comment_without_included_parent_data) { Foo::Comment.new(:id => 7, :user_id => 1) } |
140 | 141 |
|
141 | 142 | it "maps an array of included data through has_many" do |
142 | 143 | @user_with_included_data.comments.first.should be_a(Foo::Comment) |
|
149 | 150 | @user_with_included_data.comments.first.user.object_id.should == @user_with_included_data.object_id |
150 | 151 | end |
151 | 152 |
|
| 153 | + it "does fetch the parent models data only once" do |
| 154 | + comment_without_included_parent_data.user.object_id.should == comment_without_included_parent_data.user.object_id |
| 155 | + end |
| 156 | + |
| 157 | + it "does fetch the parent models data that was cached if called with parameters" do |
| 158 | + comment_without_included_parent_data.user.object_id.should_not == comment_without_included_parent_data.user.where(:a => 2).object_id |
| 159 | + end |
| 160 | + |
152 | 161 | it "uses the given inverse_of key to set the parent model" do |
153 | 162 | @user_with_included_data.posts.first.admin.object_id.should == @user_with_included_data.object_id |
154 | 163 | end |
|
164 | 173 | @user_with_included_data.comments.where(:foo_id => 1).length.should == 1 |
165 | 174 | end |
166 | 175 |
|
| 176 | + it "fetches data that was not included through has_many only once" do |
| 177 | + @user_without_included_data.comments.first.object_id.should == @user_without_included_data.comments.first.object_id |
| 178 | + end |
| 179 | + |
| 180 | + it "fetches data that was cached through has_many if called with parameters" do |
| 181 | + @user_without_included_data.comments.first.object_id.should_not == @user_without_included_data.comments.where(:foo_id => 1).first.object_id |
| 182 | + end |
| 183 | + |
167 | 184 | it "maps an array of included data through has_one" do |
168 | 185 | @user_with_included_data.role.should be_a(Foo::Role) |
169 | 186 | @user_with_included_data.role.object_id.should == @user_with_included_data.role.object_id |
|
0 commit comments