Skip to content

Commit

Permalink
Merge branch 'mjbellantoni-make-repository-execute-private'
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jun 11, 2015
2 parents 526f921 + 0b38f2e commit f550ddf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/lotus/repository.rb
Expand Up @@ -551,6 +551,7 @@ def transaction(options = {})
end
end

private
# Executes the given raw statement on the adapter.
#
# Please note that it's only supported by some databases,
Expand Down Expand Up @@ -595,7 +596,6 @@ def execute(raw)
@adapter.execute(raw)
end

private
# Fabricates a query and yields the given block to access the low level
# APIs exposed by the query itself.
#
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures.rb
Expand Up @@ -48,6 +48,10 @@ def self.not_by_user(user)
def self.rank_by_user(user)
rank.by_user(user)
end

def self.aggregate
execute("select * from articles")
end
end

DB = Sequel.connect(SQLITE_CONNECTION_STRING)
Expand Down
13 changes: 9 additions & 4 deletions test/repository_test.rb
Expand Up @@ -453,9 +453,11 @@ def updated_at
end

describe '.execute' do
it 'is a private api' do
-> { ArticleRepository.execute("select * from users") }.must_raise NoMethodError
end
it 'returns the ResultSet from the executes sql' do
sql = "select * from articles"
result = ArticleRepository.execute(sql)
result = ArticleRepository.aggregate
result.class.name.must_equal "SQLite3::ResultSet"
result.count.must_equal 1
end
Expand Down Expand Up @@ -484,8 +486,11 @@ def updated_at
end

describe '.execute' do
it "an exception is raised because of memory adapter doesn't support execute" do
-> { ArticleRepository.execute("select * from users") }.must_raise NotImplementedError
it 'is a private api' do
-> { ArticleRepository.execute("select * from users") }.must_raise NoMethodError
end
it "raises an exception because memory adapter doesn't support execute" do
-> { ArticleRepository.aggregate }.must_raise NotImplementedError
end
end

Expand Down

0 comments on commit f550ddf

Please sign in to comment.