Skip to content

Commit

Permalink
Also run tests with postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 2, 2013
1 parent 6591efe commit eda292d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ gemfile:
- gemfiles/Gemfile.ar-3.2
- gemfiles/Gemfile.ar-4.0
- gemfiles/Gemfile.ar-edge

before_script:
- psql -c 'create database typed_store_test;' -U postgres
1 change: 1 addition & 0 deletions activerecord-typedstore.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'sqlite3'
spec.add_development_dependency 'pg'
spec.add_development_dependency 'database_cleaner'
end
1 change: 1 addition & 0 deletions gemfiles/Gemfile.ar-3.2
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ gem 'bundler', '~> 1.3'
gem 'rake'
gem 'rspec'
gem 'sqlite3'
gem 'pg', '~> 0.11'
gem 'database_cleaner'
gem 'coveralls', require: false
2 changes: 2 additions & 0 deletions gemfiles/Gemfile.ar-4.0
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ gem 'bundler', '~> 1.3'
gem 'rake'
gem 'rspec'
gem 'sqlite3'
gem 'pg', '~> 0.11'
gem 'database_cleaner'
gem 'coveralls', require: false
gem 'debugger'
1 change: 1 addition & 0 deletions gemfiles/Gemfile.ar-edge
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ gem 'bundler', '~> 1.3'
gem 'rake'
gem 'rspec'
gem 'sqlite3'
gem 'pg', '~> 0.11'
gem 'database_cleaner'
gem 'coveralls', require: false
8 changes: 7 additions & 1 deletion spec/active_record/typed_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,13 @@

end

describe RegularARModel do
describe Sqlite3RegularARModel do
ActiveRecord::Base.establish_connection('test_sqlite3')
it_should_behave_like 'any model'
it_should_behave_like 'a db backed model'
end

describe PostgresqlRegularARModel do
it_should_behave_like 'any model'
it_should_behave_like 'a db backed model'
end
Expand Down
35 changes: 28 additions & 7 deletions spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
require 'json'
require 'yaml'

ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
ActiveRecord::Base.establish_connection('test')
ActiveRecord::Base.configurations = {
'test_sqlite3' => {adapter: 'sqlite3', database: "/tmp/typed_store.db"},
'test_postgresql' => {adapter: 'postgresql', database: 'typed_store_test', username: 'postgres'},
}

def define_columns(t)
t.integer :no_default
Expand Down Expand Up @@ -32,21 +34,38 @@ def define_columns(t)
end

class CreateAllTables < ActiveRecord::Migration

def self.recreate_table(name, *args, &block)
execute "drop table if exists #{name}"
create_table(name, *args, &block)
end

def self.up
create_table(:regular_ar_models) { |t| define_columns(t); t.text :untyped_settings }
create_table(:yaml_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
create_table(:json_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
create_table(:marshal_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
ActiveRecord::Base.establish_connection('test_postgresql')
recreate_table(:postgresql_regular_ar_models) { |t| define_columns(t); t.text :untyped_settings }

ActiveRecord::Base.establish_connection('test_sqlite3')
recreate_table(:sqlite3_regular_ar_models) { |t| define_columns(t); t.text :untyped_settings }
recreate_table(:yaml_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
recreate_table(:json_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
recreate_table(:marshal_typed_store_models) { |t| t.text :settings; t.text :untyped_settings }
end
end
ActiveRecord::Migration.verbose = false
CreateAllTables.up

class RegularARModel < ActiveRecord::Base
class PostgresqlRegularARModel < ActiveRecord::Base
establish_connection 'test_postgresql'
store :untyped_settings, accessors: [:title]
end

class Sqlite3RegularARModel < ActiveRecord::Base
establish_connection 'test_sqlite3'
store :untyped_settings, accessors: [:title]
end

class YamlTypedStoreModel < ActiveRecord::Base
establish_connection 'test_sqlite3'
store :untyped_settings, accessors: [:title]
typed_store :settings do |s|
define_columns(s)
Expand All @@ -71,13 +90,15 @@ def dump(data)
end

class JsonTypedStoreModel < ActiveRecord::Base
establish_connection 'test_sqlite3'
store :untyped_settings, accessors: [:title]
typed_store :settings, coder: ColumnCoder.new(JSON) do |s|
define_columns(s)
end
end

class MarshalTypedStoreModel < ActiveRecord::Base
establish_connection 'test_sqlite3'
store :untyped_settings, accessors: [:title]
typed_store :settings, coder: ColumnCoder.new(Marshal) do |s|
define_columns(s)
Expand Down

0 comments on commit eda292d

Please sign in to comment.