consistent_schema_rb 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/lib/active_record/connection_adapters/ordered_column_postgresql_adapter.rb +30 -0
- data/lib/consistent_schema_rb/version.rb +1 -1
- data/spec/active_record/connection_adapters/ordered_column_postgresql_apapter_spec.rb +54 -0
- data/spec/spec_helper.rb +18 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3b7df4e30d9571adedc9d56f63df6ade64f0a3d
|
4
|
+
data.tar.gz: 97c13625c0b435fdd40c7c7fa4697c1efbb83caf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72fee3e029d7d8e8473a85ae9578875a2ae5162bb57446d5252c9c6841fc9f370f2ae890a5de720231ecb08eb074f58f8d3b332fed0eebd6a5c46af52151d22
|
7
|
+
data.tar.gz: 9ddfc7c927c8c3a5cd2d5d023370de918b3a02f5419f1398285b1035c2eb61d3e4ef18acd0da6e8d89dc4b6f083562564809c24b96d87d98487b85c1892b8451
|
data/.rspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Base
|
5
|
+
def self.ordered_column_postgresql_connection(config)
|
6
|
+
ConnectionAdapters::OrderedColumnPostgreSQLAdapterWrapper.new(postgresql_connection(config))
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ConnectionAdapters
|
11
|
+
class OrderedColumnPostgreSQLAdapterWrapper < Delegator
|
12
|
+
def initailize(postgresql_connection)
|
13
|
+
super
|
14
|
+
@postgresql_connection = postgresql_connection
|
15
|
+
end
|
16
|
+
|
17
|
+
def columns(table_name, name = nil)
|
18
|
+
@postgresql_connection.columns(table_name, name).sort { |x,y| x.name <=> y.name }
|
19
|
+
end
|
20
|
+
|
21
|
+
def __getobj__
|
22
|
+
@postgresql_connection
|
23
|
+
end
|
24
|
+
|
25
|
+
def __setobj__(obj)
|
26
|
+
@postgresql_connection = obj
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
|
6
|
+
describe "created adapter" do
|
7
|
+
let(:config) { {} }
|
8
|
+
|
9
|
+
context "creates a postgresql connection" do
|
10
|
+
it "creates a postgresql connection" do
|
11
|
+
config = {}
|
12
|
+
ActiveRecord::Base.should_receive(:postgresql_connection).with(config).and_return { Object.new }
|
13
|
+
|
14
|
+
ActiveRecord::Base.ordered_column_postgresql_connection(config)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe OrderedColumnPostgreSQLAdapterWrapper do
|
20
|
+
subject { ActiveRecord::Base.ordered_column_postgresql_connection({}) }
|
21
|
+
|
22
|
+
let(:stub_postresql_adapter) { double(PostgreSQLAdapter) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
ActiveRecord::Base.stub(:postgresql_connection).and_return { stub_postresql_adapter }
|
26
|
+
end
|
27
|
+
|
28
|
+
it "delgates methods to the real postgres adapter" do
|
29
|
+
stub_postresql_adapter.should_receive(:table).with('name')
|
30
|
+
|
31
|
+
subject.table('name')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "overrides columns and returns the columns sorted by name" do
|
35
|
+
stub_postresql_adapter.stub(:columns).and_return([
|
36
|
+
TestColumn.new('bbb'),
|
37
|
+
TestColumn.new('xb'),
|
38
|
+
TestColumn.new('abb'),
|
39
|
+
TestColumn.new('aaa')
|
40
|
+
])
|
41
|
+
|
42
|
+
subject.columns('name').should eq [
|
43
|
+
TestColumn.new('aaa'),
|
44
|
+
TestColumn.new('abb'),
|
45
|
+
TestColumn.new('bbb'),
|
46
|
+
TestColumn.new('xb')
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
class TestColumn < Struct.new(:name)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
lib = File.expand_path('../lib', File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_record'
|
6
|
+
require 'consistent_schema_rb'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consistent_schema_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Aitken
|
@@ -89,13 +89,17 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- .gitignore
|
92
|
+
- .rspec
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- consistent_schema_rb.gemspec
|
98
|
+
- lib/active_record/connection_adapters/ordered_column_postgresql_adapter.rb
|
97
99
|
- lib/consistent_schema_rb.rb
|
98
100
|
- lib/consistent_schema_rb/version.rb
|
101
|
+
- spec/active_record/connection_adapters/ordered_column_postgresql_apapter_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
99
103
|
homepage: http://github.com/alexaitken/consisten_schema_rb
|
100
104
|
licenses:
|
101
105
|
- MIT
|
@@ -121,4 +125,6 @@ signing_key:
|
|
121
125
|
specification_version: 4
|
122
126
|
summary: Orders columns from the active record adapters so the schema dumper will
|
123
127
|
produce a consistent schema.rb
|
124
|
-
test_files:
|
128
|
+
test_files:
|
129
|
+
- spec/active_record/connection_adapters/ordered_column_postgresql_apapter_spec.rb
|
130
|
+
- spec/spec_helper.rb
|