Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding in specs for minimapper/ar using sqlite.
  • Loading branch information
joakimk committed Oct 13, 2012
1 parent fcab7c9 commit b1b1533
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Rakefile
Expand Up @@ -2,9 +2,21 @@ require "bundler/gem_tasks"

namespace :spec do
task :unit do
puts "Running unit tests."
spec_helper_path = File.expand_path("unit/spec_helper.rb")
system("rspec", "-r#{spec_helper_path}", *Dir["unit/**/*_spec.rb"]) || exit(1)
end

task :integrated do
puts "Running integrated tests."
integrated_helper_path = File.expand_path("spec/spec_helper.rb")
system("rspec", "-r#{integrated_helper_path}", *Dir["spec/**/*_spec.rb"]) || exit(1)
end
end

task :spacer do
puts
end

task :default => [ :"spec:unit" ]
task :spec => [ :"spec:unit", :spacer, :"spec:integrated" ]
task :default => :spec
2 changes: 2 additions & 0 deletions lib/minimapper/ar.rb
@@ -1,3 +1,5 @@
require "minimapper/common"

module Minimapper
class AR
def add(entity)
Expand Down
9 changes: 9 additions & 0 deletions minimapper.gemspec
Expand Up @@ -19,5 +19,14 @@ Gem::Specification.new do |gem|

gem.add_dependency "informal"
gem.add_dependency "rake"

gem.add_development_dependency "rspec"

# We don't require active_record to use minimapper, only to
# use minimapper/ar. We do require it for the tests though :)
gem.add_development_dependency "activerecord"

# ActiveRecord isn't a perfect abstraction so we'll need to test against
# many different databases. To begin with, we're using in-memory sqlite3.
gem.add_development_dependency "sqlite3"
end
32 changes: 32 additions & 0 deletions spec/lib/minimapper/ar_spec.rb
@@ -0,0 +1,32 @@
require "spec_helper"
require "minimapper/entity"
require "minimapper/ar"

class TestEntity < Minimapper::Entity
attributes :name, :github_url
validates :name, presence: true
end

class TestMapper < Minimapper::AR
private

def entity_klass
TestEntity
end

def record_klass
Record
end

class Record < ActiveRecord::Base
attr_accessible :name
self.table_name = :projects
end
end

describe Minimapper::AR do
let(:repository) { TestMapper.new }
let(:entity_klass) { TestEntity }

include_examples :mapper
end
21 changes: 21 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,21 @@
require "active_record"
require "minimapper"

ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
Dir[File.join(ROOT, "spec/support/shared_examples/*.rb")].each { |f| require f }

ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"

RSpec.configure do |config|
config.before(:each) do
ActiveRecord::Base.connection.execute "DELETE FROM projects;"
end
end

silence_stream(STDOUT) do
ActiveRecord::Schema.define(:version => 0) do
create_table :projects, :force => true do |t|
t.string :name
end
end
end
2 changes: 1 addition & 1 deletion unit/spec_helper.rb
Expand Up @@ -2,7 +2,7 @@
$: << File.join(ROOT, "lib")
$: << File.join(ROOT, "unit")

require 'minimapper'
require "minimapper"

Dir[File.join(ROOT, "spec/support/shared_examples/*.rb")].each { |f| require f }

Expand Down

0 comments on commit b1b1533

Please sign in to comment.