Skip to content

Commit fa415a6

Browse files
committed
better semantics for active record reflections spec
1 parent 67e5583 commit fa415a6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

spec/active_record_spec.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
ActiveRecord::Base.establish_connection(
66
adapter: :nulldb,
7-
schema: 'support/active_record/schema'
7+
schema: 'spec/support/active_record/schema.rb'
88
)
99

10+
NullDB.configure { |ndb| def ndb.project_root; Dir.pwd; end; }
11+
1012
shared_examples 'produces_correct_sql' do
1113
it 'produces correct sql for first page' do
1214
paginated_sql = ApiPagination.paginate(collection, per_page: per_page)
@@ -35,13 +37,16 @@
3537
end
3638
end
3739

38-
context 'reification' do
39-
before do
40-
allow(collection).to receive(:table_name).and_return('aaBB_CC_DD')
40+
context 'reflections' do
41+
it 'invokes the correct methods to determine type' do
42+
expect(collection).to receive(:klass).at_least(:once)
43+
.and_call_original
44+
ApiPagination.paginate(collection)
4145
end
4246

43-
it 'correctly produces the correct model independent of table name' do
44-
expect { ApiPagination.paginate(collection) }.not_to raise_error
47+
it 'does not fail if table name is not snake cased class name' do
48+
allow(collection).to receive(:table_name).and_return(SecureRandom.uuid)
49+
expect { ApiPagination.paginate(collection) }.to_not raise_error
4550
end
4651
end
4752
end

0 commit comments

Comments
 (0)