activerecord-postgresql-expression 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d0a7eb8c7e4a647212668965c9a1edfa46b1bd
4
- data.tar.gz: 17a7e65e997ed922ee6732202d1ddeb2bc204ce5
3
+ metadata.gz: cd04f4bc03913154b0cf8bde7d4a4f83b4f8fcd2
4
+ data.tar.gz: f29baf6079c945d2f547d15fd7cf68bd1be0e288
5
5
  SHA512:
6
- metadata.gz: 3c4b748ba4b5f70faca61de39027ec105f34921a22cc00c921f6de43d1e9901c71ed99e142e4e644b5cd5c4da1cc42027b411298221fc2ec6f5ca1e3718236ff
7
- data.tar.gz: 00000c7c184cf29da52c28af87f35caa1df13de7a23d8fc8b7ff232930bd91ac88b91dda2ff753b4d9049ed83326370a3d7ed771afdb02b3feef77652270fe41
6
+ metadata.gz: 61a0e6879204ba752aaa6e6980512eb4df5ca41ef649ca87e7c1de6b4ff7ba24763c5f861ff3a0c00b1dd80fb29ce6254ecb854192aa81006d625c65a973b614
7
+ data.tar.gz: f055fe88f686cb36bc276eb0bb7b56435cbd3dba5ff77312f7dc5554efbf3e694809e1d359ed2f259b121b0cb130c3c8f3aa1bceeb96d14b9ed2ca18b61d7133
@@ -8,10 +8,15 @@ module ActiveRecord
8
8
  def indexes(table, stream)
9
9
  buf = StringIO.new
10
10
  super(table, buf)
11
- buf = buf.string.chomp
12
- output = add_index_with_expression(table) + "\n"
13
- stream.print buf
14
- stream.print output
11
+ output = add_index_with_expression(table)
12
+ if output == ""
13
+ buf = buf.string
14
+ stream.print buf
15
+ else
16
+ buf = buf.string.chomp
17
+ stream.print buf
18
+ stream.print output + "\n\n"
19
+ end
15
20
  stream
16
21
  end
17
22
 
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module PostgreSQL
3
3
  module Expression
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -9,23 +9,53 @@ class ExpressionTest < ActiveRecord::TestCase
9
9
 
10
10
  setup do
11
11
  @connection = ActiveRecord::Base.connection
12
- @connection.create_table("posts", force: true) do |t|
12
+ @connection.create_table("gin_and_btree", force: true) do |t|
13
13
  t.string "title"
14
14
  t.text "content"
15
15
  end
16
- @connection.add_index :posts, :content, using: :gin, expression: 'to_tsvector(\'english\'::regconfig, (content)::text)'
17
- @connection.add_index :posts, :content, name: 'hogehoge', using: :gin, expression: 'to_tsvector(\'english\'::regconfig, (content)::text)'
18
- @connection.add_index :posts, :title
16
+ @connection.add_index :gin_and_btree, :content, using: :gin, expression: 'to_tsvector(\'english\'::regconfig, (content)::text)'
17
+ @connection.add_index :gin_and_btree, :content, name: 'hogehoge', using: :gin, expression: 'to_tsvector(\'english\'::regconfig, (content)::text)'
18
+ @connection.add_index :gin_and_btree, :title
19
+ @connection.create_table("no_index", force: true) do |t|
20
+ t.string "title"
21
+ t.text "content"
22
+ end
23
+ @connection.create_table("btree", force: true) do |t|
24
+ t.string "title"
25
+ t.text "content"
26
+ end
27
+ @connection.add_index :btree, :title
28
+ @connection.create_table("gin", force: true) do |t|
29
+ t.string "title"
30
+ t.text "content"
31
+ end
32
+ @connection.add_index :gin, :content, using: :gin, expression: 'to_tsvector(\'english\'::regconfig, (content)::text)'
19
33
  end
20
34
 
21
35
  teardown do
22
- @connection.drop_table "posts"
36
+ @connection.drop_table "gin_and_btree"
37
+ @connection.drop_table "btree"
38
+ @connection.drop_table "gin"
39
+ @connection.drop_table "no_index"
23
40
  end
24
41
 
25
- def test_schema_dump_expression
26
- schema = dump_table_schema "posts"
27
- assert_match %r{add_index\s+\"posts\",\s+\[\"title\"\],\s+name:\s+\"index_posts_on_title\",\s+using:\s+:btree$}, schema
28
- assert_match %r{add_index\s+\"posts\",\s+\[\"content\"\],\s+name:\s+\"index_posts_on_content\",\s+using:\s+:gin,\s+expression:\s+\"to_tsvector\('english'::regconfig,\s+content\)\"$}, schema
29
- assert_match %r{add_index\s+\"posts\",\s+'',\s+name:\s+\"hogehoge\",\s+using:\s+:gin,\s+expression:\s+\"to_tsvector\('english'::regconfig,\s+content\)\"$}, schema
42
+ def test_schema_dump_gin_and_btree
43
+ schema = dump_table_schema "gin_and_btree"
44
+ assert_match %r{add_index\s+\"gin_and_btree\",\s+\[\"title\"\],\s+name:\s+\"index_gin_and_btree_on_title\",\s+using:\s+:btree$}, schema
45
+ assert_match %r{add_index\s+\"gin_and_btree\",\s+\[\"content\"\],\s+name:\s+\"index_gin_and_btree_on_content\",\s+using:\s+:gin,\s+expression:\s+\"to_tsvector\('english'::regconfig,\s+content\)\"$}, schema
46
+ assert_match %r{add_index\s+\"gin_and_btree\",\s+'',\s+name:\s+\"hogehoge\",\s+using:\s+:gin,\s+expression:\s+\"to_tsvector\('english'::regconfig,\s+content\)\"$}, schema
47
+ assert_match %r{\n\nend$}, schema
48
+ end
49
+ def test_schema_dump_gin
50
+ schema = dump_table_schema "gin"
51
+ assert_match %r{\n\nend$}, schema
52
+ end
53
+ def test_schema_dump_btree
54
+ schema = dump_table_schema "btree"
55
+ assert_match %r{\n\nend$}, schema
56
+ end
57
+ def test_schema_dump_no_index
58
+ schema = dump_table_schema "no_index"
59
+ assert_match %r{end\n\nend$}, schema
30
60
  end
31
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgresql-expression
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoya Murakami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler