Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

syntax cleanup

  • Loading branch information...
commit f6bcc251e5ed7ebe01b15fb6d2ec40e03b5a8b2b 1 parent 41e65ec
Brad Robertson bradrobertson authored
17 Rakefile
@@ -7,16 +7,17 @@ require "rspec/core/rake_task"
7 7
8 8 RSpec::Core::RakeTask.new(:spec => "db:test:prepare") do |spec|
9 9 spec.pattern = "spec/**/*_spec.rb"
  10 + # spec.rspec_opts = '--order rand:16996'
10 11 end
11 12
12 13 namespace :spec do
13   -
  14 +
14 15 [:tasks, :unit, :adapters, :integration].each do |type|
15 16 RSpec::Core::RakeTask.new(type => :spec) do |spec|
16 17 spec.pattern = "spec/#{type}/**/*_spec.rb"
17 18 end
18 19 end
19   -
  20 +
20 21 end
21 22
22 23 task :default => :spec
@@ -30,39 +31,39 @@ end
30 31 namespace :postgres do
31 32 require 'active_record'
32 33 require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
33   -
  34 +
34 35 desc 'Build the PostgreSQL test databases'
35 36 task :build_db do
36 37 %x{ createdb -E UTF8 #{pg_config['database']} -Upostgres } rescue "test db already exists"
37 38 ActiveRecord::Base.establish_connection pg_config
38 39 ActiveRecord::Migrator.migrate('spec/dummy/db/migrate')
39 40 end
40   -
  41 +
41 42 desc "drop the PostgreSQL test database"
42 43 task :drop_db do
43 44 puts "dropping database #{pg_config['database']}"
44 45 %x{ dropdb #{pg_config['database']} -Upostgres }
45 46 end
46   -
  47 +
47 48 end
48 49
49 50 namespace :mysql do
50 51 require 'active_record'
51 52 require "#{File.join(File.dirname(__FILE__), 'spec', 'support', 'config')}"
52   -
  53 +
53 54 desc 'Build the MySQL test databases'
54 55 task :build_db do
55 56 %x{ mysqladmin -u root create #{my_config['database']} } rescue "test db already exists"
56 57 ActiveRecord::Base.establish_connection my_config
57 58 ActiveRecord::Migrator.migrate('spec/dummy/db/migrate')
58 59 end
59   -
  60 +
60 61 desc "drop the MySQL test database"
61 62 task :drop_db do
62 63 puts "dropping database #{my_config['database']}"
63 64 %x{ mysqladmin -u root drop #{my_config['database']} --force}
64 65 end
65   -
  66 +
66 67 end
67 68
68 69 # TODO clean this up
4 apartment.gemspec
@@ -17,10 +17,10 @@ Gem::Specification.new do |s|
17 17 s.licenses = ["MIT"]
18 18 s.require_paths = ["lib"]
19 19 s.rubygems_version = %q{1.3.7}
20   -
  20 +
21 21 s.add_dependency 'activerecord', '>= 3.1.2' # must be >= 3.1.2 due to bug in prepared_statements
22 22 s.add_dependency 'rack', '>= 1.3.6'
23   -
  23 +
24 24 s.add_development_dependency 'rails', '>= 3.1.2'
25 25 s.add_development_dependency 'rake', '~> 0.9.2'
26 26 s.add_development_dependency 'sqlite3'
4 lib/apartment/adapters/postgresql_adapter.rb
@@ -46,7 +46,7 @@ def current_database
46 46 # @param {String} database Database (schema) to drop
47 47 #
48 48 def drop(database)
49   - ActiveRecord::Base.connection.execute("DROP SCHEMA \"#{database}\" CASCADE")
  49 + ActiveRecord::Base.connection.execute(%{DROP SCHEMA "#{database}" CASCADE})
50 50
51 51 rescue ActiveRecord::StatementInvalid
52 52 raise SchemaNotFound, "The schema #{database.inspect} cannot be found."
@@ -101,7 +101,7 @@ def connect_to_new(database = nil)
101 101 # Create the new schema
102 102 #
103 103 def create_database(database)
104   - ActiveRecord::Base.connection.execute("CREATE SCHEMA \"#{database}\"")
  104 + ActiveRecord::Base.connection.execute(%{CREATE SCHEMA "#{database}"})
105 105
106 106 rescue ActiveRecord::StatementInvalid
107 107 raise SchemaExists, "The schema #{database} already exists."
8 spec/adapters/postgresql_adapter_spec.rb
@@ -14,22 +14,22 @@
14 14 def database_names
15 15 ActiveRecord::Base.connection.execute("SELECT nspname FROM pg_namespace;").collect{|row| row['nspname']}
16 16 end
17   -
  17 +
18 18 let(:default_database){ subject.process{ ActiveRecord::Base.connection.schema_search_path } }
19 19
20 20 it_should_behave_like "a generic apartment adapter"
21 21 it_should_behave_like "a schema based apartment adapter"
22 22 end
23   -
  23 +
24 24 context "using databases" do
25 25
26   - before{ Apartment.use_postgres_schemas = false }
  26 + before{ Apartment.use_postgres_schemas = false }
27 27
28 28 # Not sure why, but somehow using let(:database_names) memoizes for the whole example group, not just each test
29 29 def database_names
30 30 connection.execute("select datname from pg_database;").collect{|row| row['datname']}
31 31 end
32   -
  32 +
33 33 let(:default_database){ subject.process{ ActiveRecord::Base.connection.current_database } }
34 34
35 35 it_should_behave_like "a generic apartment adapter"
24 spec/examples/schema_adapter_examples.rb
@@ -2,20 +2,20 @@
2 2
3 3 shared_examples_for "a schema based apartment adapter" do
4 4 include Apartment::Spec::AdapterRequirements
5   -
  5 +
6 6 let(:schema1){ db1 }
7 7 let(:schema2){ db2 }
8 8 let(:public_schema){ default_database }
9 9
10 10 describe "#init" do
11   -
  11 +
12 12 it "should process model exclusions" do
13 13 Apartment.configure do |config|
14 14 config.excluded_models = ["Company"]
15 15 end
16   -
  16 +
17 17 Apartment::Database.init
18   -
  18 +
19 19 Company.table_name.should == "public.companies"
20 20 end
21 21 end
@@ -29,7 +29,7 @@
29 29 connection.schema_search_path = schema1
30 30 connection.tables.should include('companies')
31 31 end
32   -
  32 +
33 33 it "should yield to block if passed and reset" do
34 34 subject.drop(schema2) # so we don't get errors on creation
35 35
@@ -40,12 +40,12 @@
40 40 connection.schema_search_path.should == schema2
41 41 User.create
42 42 end
43   -
  43 +
44 44 connection.schema_search_path.should_not == schema2
45 45
46 46 subject.process(schema2){ User.count.should == @count + 1 }
47 47 end
48   -
  48 +
49 49 it "should allow numeric database names" do
50 50 expect {
51 51 subject.create(1234)
@@ -54,16 +54,16 @@
54 54 # cleanup
55 55 subject.drop(1234)
56 56 end
57   -
  57 +
58 58 end
59   -
  59 +
60 60 describe "#drop" do
61 61 it "should raise an error for unknown database" do
62 62 expect {
63 63 subject.drop "unknown_database"
64 64 }.to raise_error(Apartment::SchemaNotFound)
65 65 end
66   -
  66 +
67 67 it "should be able to drop numeric dbs" do
68 68 subject.create(1234)
69 69 expect {
@@ -104,13 +104,13 @@
104 104 subject.switch
105 105 connection.schema_search_path.should == public_schema
106 106 end
107   -
  107 +
108 108 it "should raise an error if schema is invalid" do
109 109 expect {
110 110 subject.switch 'unknown_schema'
111 111 }.to raise_error(Apartment::SchemaNotFound)
112 112 end
113   -
  113 +
114 114 it "should connect to numeric dbs" do
115 115 subject.create(1234)
116 116 expect {

0 comments on commit f6bcc25

Please sign in to comment.
Something went wrong with that request. Please try again.