activerecord-column_metadata 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTYxNzQ2NTgyNzk5MDViYzJiN2Q0ZDUwYTExYTFjMzBiNGQ2MDZmZg==
5
+ data.tar.gz: !binary |-
6
+ NGM5ODg5NjI2YWQ0MzFjMDliNzczM2QzNjIxMzJhY2JjNWJiZDU4YQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTVjZjMzMGVhM2FiZTg4NWQ1M2FkNDQyNGQ4NjU1NTg0ZjkyNjE1YjkzOGFh
10
+ MzZjMzcyNDcxODI5NDYxZDQyYTM4ZDZjZGI1NjUzY2YzYjY5NzMyMmZjNDFh
11
+ ZDkzMzUxMjQzN2RhNGIwMzM5MTNjNzViYmM4Y2I1MWZlNTYxZjY=
12
+ data.tar.gz: !binary |-
13
+ NmVhZWNmNTgwN2UwNWZkNWFkOWM1Y2VhODhhNGIzMDVkZjE4ZTYyNGQyMDgx
14
+ M2I0NWFkYjMzOGY5ODM2YWRhY2Y1YzAyNDNkZTI3ZGJiYzk0Y2I1NDRiNWU5
15
+ MTc2NmE4NjdiMmQxZjQzOTMyYzJjMTA5NzkwMDQ1MDhmZDRlOWM=
@@ -1,3 +1,7 @@
1
+ ## 0.1.0 (24 September 2014)
2
+
3
+ Fix add_column with no metadata
4
+
1
5
  ## 0.0.3 (12 July 2013)
2
6
 
3
7
  Add column_metadata(table_name, column_name, metadata) for use in migrations
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", "~>3.0.3"
21
+ spec.add_dependency "activerecord", ">=3.0.3", "<4"
22
22
  spec.add_dependency "pg"
23
-
23
+
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "rspec"
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class ColumnMetadata
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -9,20 +9,20 @@ module ActiveRecord
9
9
  def column_metadata(column, hash)
10
10
  add_comment(column, hash)
11
11
  end
12
-
12
+
13
13
  def add_comment(column, comment)
14
14
  @comments ||= []
15
15
  @comments << [column, comment]
16
16
  end
17
-
17
+
18
18
  def comments
19
19
  @comments
20
20
  end
21
21
  end
22
-
22
+
23
23
  include ColumnMetadata
24
24
  end
25
-
25
+
26
26
  module SchemaStatements
27
27
  # works only with databases that support comments on columns
28
28
  def create_table(table_name,options={},&block)
@@ -43,7 +43,7 @@ module ActiveRecord
43
43
  table_definition.comments.each{ |c| write_json_comment(table_name, c.to_a.first, c.to_a.last) } if table_definition.comments
44
44
  end
45
45
  end
46
-
46
+
47
47
  class PostgreSQLAdapter < AbstractAdapter
48
48
  def add_column_with_metadata(*args)
49
49
  add_column_without_metadata(*args)
@@ -51,13 +51,13 @@ module ActiveRecord
51
51
  write_json_comment(args[0], args[1], options[:metadata])
52
52
  end
53
53
  alias_method_chain :add_column, :metadata
54
-
54
+
55
55
  def column_metadata(table_name, column_name, metadata)
56
56
  write_json_comment(table_name, column_name, metadata)
57
57
  end
58
-
58
+
59
59
  def write_json_comment(table_name, column_name, comment)
60
- execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS #{quote(comment.to_json)}"
60
+ execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS #{quote(comment.to_json)}" unless comment.blank?
61
61
  end
62
62
  end
63
63
  end
@@ -25,20 +25,20 @@ describe ActiveRecord::ColumnMetadata do
25
25
  end
26
26
  end
27
27
  end
28
-
28
+
29
29
  class AddColumnMigration < ActiveRecord::Migration
30
30
  def self.up
31
31
  add_column :people, :surname, :string, :metadata => {full_text_search: "double_metaphone"}
32
32
  end
33
33
  end
34
-
34
+
35
35
  describe 'write should add JSON in comment' do
36
36
  it 'with create_table' do
37
37
  CreateTableMigration.up
38
38
  res = get_comments("people")
39
39
  expect(res).to include( ["name",'{"something":true}'])
40
40
  end
41
-
41
+
42
42
  it 'with add_column' do
43
43
  CreateTableMigration.up
44
44
  AddColumnMigration.up
@@ -51,20 +51,41 @@ describe ActiveRecord::ColumnMetadata do
51
51
  column_metadata :people, :name, {completely: "different"}
52
52
  end
53
53
  end
54
-
55
- it 'with add_column_metadata' do
54
+
55
+ it 'with column_metadata' do
56
56
  CreateTableMigration.up
57
57
  AddColumnMetadataMigration.up
58
58
  res = get_comments("people")
59
59
  expect(res).to include( ['name', '{"completely":"different"}'])
60
60
  end
61
+
62
+ class AddColumnWithoutMetadataMigration < ActiveRecord::Migration
63
+ def self.up
64
+ add_column :people, :surname, :string
65
+ end
66
+ end
67
+
68
+ class CreateTableWithoutMetadataMigration < ActiveRecord::Migration
69
+ def self.up
70
+ create_table(:people) do |t|
71
+ t.string :name
72
+ end
73
+ end
74
+ end
75
+
76
+ it 'without any metadata given' do
77
+ CreateTableWithoutMetadataMigration.up
78
+ AddColumnWithoutMetadataMigration.up
79
+ res = get_comments('people')
80
+ expect(res).to contain_exactly ["id", nil], ["name", nil], ["surname", nil]
81
+ end
61
82
  end
62
-
83
+
63
84
  describe 'read' do
64
85
  it '#to_a should return a column comments as an array of arrays' do
65
86
  CreateTableMigration.up
66
87
  res = ActiveRecord::ColumnMetadata.to_a(:people)
67
88
  res.should == [["name", {"something" => true}]]
68
89
  end
69
- end
90
+ end
70
91
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-column_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sava Chankov
@@ -10,28 +9,31 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-12 00:00:00.000000000 Z
12
+ date: 2014-09-24 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - ! '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: 3.0.3
21
+ - - <
22
+ - !ruby/object:Gem::Version
23
+ version: '4'
23
24
  type: :runtime
24
25
  prerelease: false
25
26
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
27
  requirements:
28
- - - ~>
28
+ - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: 3.0.3
31
+ - - <
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
31
34
  - !ruby/object:Gem::Dependency
32
35
  name: pg
33
36
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
37
  requirements:
36
38
  - - ! '>='
37
39
  - !ruby/object:Gem::Version
@@ -39,7 +41,6 @@ dependencies:
39
41
  type: :runtime
40
42
  prerelease: false
41
43
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
44
  requirements:
44
45
  - - ! '>='
45
46
  - !ruby/object:Gem::Version
@@ -47,7 +48,6 @@ dependencies:
47
48
  - !ruby/object:Gem::Dependency
48
49
  name: bundler
49
50
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
@@ -55,7 +55,6 @@ dependencies:
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
58
  requirements:
60
59
  - - ~>
61
60
  - !ruby/object:Gem::Version
@@ -63,7 +62,6 @@ dependencies:
63
62
  - !ruby/object:Gem::Dependency
64
63
  name: rake
65
64
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
65
  requirements:
68
66
  - - ! '>='
69
67
  - !ruby/object:Gem::Version
@@ -71,7 +69,6 @@ dependencies:
71
69
  type: :development
72
70
  prerelease: false
73
71
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
72
  requirements:
76
73
  - - ! '>='
77
74
  - !ruby/object:Gem::Version
@@ -79,7 +76,6 @@ dependencies:
79
76
  - !ruby/object:Gem::Dependency
80
77
  name: rspec
81
78
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
79
  requirements:
84
80
  - - ! '>='
85
81
  - !ruby/object:Gem::Version
@@ -87,7 +83,6 @@ dependencies:
87
83
  type: :development
88
84
  prerelease: false
89
85
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
86
  requirements:
92
87
  - - ! '>='
93
88
  - !ruby/object:Gem::Version
@@ -95,7 +90,6 @@ dependencies:
95
90
  - !ruby/object:Gem::Dependency
96
91
  name: database_cleaner
97
92
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
93
  requirements:
100
94
  - - ! '>='
101
95
  - !ruby/object:Gem::Version
@@ -103,7 +97,6 @@ dependencies:
103
97
  type: :development
104
98
  prerelease: false
105
99
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
100
  requirements:
108
101
  - - ! '>='
109
102
  - !ruby/object:Gem::Version
@@ -136,30 +129,28 @@ files:
136
129
  homepage: http://github.com/tutuf/activerecord-column_metadata
137
130
  licenses:
138
131
  - MIT
132
+ metadata: {}
139
133
  post_install_message:
140
134
  rdoc_options: []
141
135
  require_paths:
142
136
  - lib
143
137
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
138
  requirements:
146
139
  - - ! '>='
147
140
  - !ruby/object:Gem::Version
148
141
  version: '0'
149
142
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
143
  requirements:
152
144
  - - ! '>='
153
145
  - !ruby/object:Gem::Version
154
146
  version: '0'
155
147
  requirements: []
156
148
  rubyforge_project:
157
- rubygems_version: 1.8.25
149
+ rubygems_version: 2.4.1
158
150
  signing_key:
159
- specification_version: 3
151
+ specification_version: 4
160
152
  summary: ActiveRecord extension to store column metadata in database
161
153
  test_files:
162
154
  - spec/activerecord_column_metadata_spec.rb
163
155
  - spec/database.yml
164
156
  - spec/spec_helper.rb
165
- has_rdoc: