Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernie Miller committed Jul 21, 2011
1 parent 8706934 commit 67edfcb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
13 changes: 7 additions & 6 deletions spec/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
end

Sham.define do
name { Faker::Name.name }
title { Faker::Lorem.sentence }
body { Faker::Lorem.paragraph }
salary {|index| 30000 + (index * 1000)}
tag_name { Faker::Lorem.words(3).join(' ') }
note { Faker::Lorem.words(7).join(' ') }
name { Faker::Name.name }
title { Faker::Lorem.sentence }
body { Faker::Lorem.paragraph }
salary {|index| 30000 + (index * 1000)}
tag_name { Faker::Lorem.words(3).join(' ') }
note { Faker::Lorem.words(7).join(' ') }
object_name { Faker::Lorem.words(1).first }
end

Schema.create
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module ActiveRecord
class SQLCounter
IGNORED_SQL = [/^PRAGMA (?!(table_info))/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/,
IGNORED_SQL = [/^PRAGMA /, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/,
/SELECT name\s+FROM sqlite_master\s+WHERE type = 'table' AND NOT name = 'sqlite_sequence'/]

# FIXME: this needs to be refactored so specific database can add their own
Expand Down Expand Up @@ -37,6 +37,7 @@ def call(name, start, finish, message_id, values)
salary {|index| 30000 + (index * 1000)}
tag_name { Faker::Lorem.words(3).join(' ') }
note { Faker::Lorem.words(7).join(' ') }
object_name { Faker::Lorem.words(1).first }
end

RSpec.configure do |config|
Expand Down
12 changes: 12 additions & 0 deletions spec/squeel/adapters/active_record/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,18 @@ module ActiveRecord
person.comments.loaded?.should be true
end

it 'includes a belongs_to association even if the child model has no primary key' do
relation = UnidentifiedObject.where{person_id < 120}.includes(:person)
queries = queries_for do
vals = relation.to_a
vals.should have(8).items
end

queries.should have(2).queries

queries.last.should match /IN \(1, 34, 67, 100\)/
end

end

end
Expand Down
13 changes: 13 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Person < ActiveRecord::Base
has_many :authored_article_comments, :through => :articles,
:source => :comments
has_many :notes, :as => :notable
has_many :unidentified_objects
end

class UnidentifiedObject < ActiveRecord::Base
belongs_to :person
end

class Article < ActiveRecord::Base
Expand Down Expand Up @@ -50,6 +55,11 @@ def self.create
t.integer :salary
end

create_table :unidentified_objects, :id => false, :force => true do |t|
t.integer :person_id
t.string :name
end

create_table :articles, :force => true do |t|
t.integer :person_id
t.string :title
Expand Down Expand Up @@ -82,6 +92,9 @@ def self.create

10.times do
person = Person.make
2.times do
UnidentifiedObject.create(:person => person, :name => Sham.object_name)
end
Note.make(:notable => person)
3.times do
article = Article.make(:person => person)
Expand Down

0 comments on commit 67edfcb

Please sign in to comment.