sequel_migration_builder 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzVhY2M3MmE2YWZmZTk2ZDZhNzhjN2JiOTc0YmQwM2FjOWUwYTRhYg==
4
+ NGRmODU3NzY1NDA1MGIyNjllMjE3ODA1ZjY0ZWIyNzE3MWRjMTdhZQ==
5
5
  data.tar.gz: !binary |-
6
- ZWRlMDFiMTg1ZWZiNGYyMDQ5YTZkNzVjMWJjZTc5YjVkZWRmZjlkZA==
6
+ NDFiMmJkZjlkNDA2YTVlMTdkODExYzY2NzQ3Yzg2ZDk4MWVmOWQxYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjE5OGMyMDA2ZWE5MGZhYmM2MWViNDYwMDVkZjk0YjQ5Nzk5NmYxNDcyZGU5
10
- MmM1YTNhNjM1ZmQ4YWUwY2U4NmYzYTg1Y2ZmNmFmNWNlMjlkYTU1YmRkZTA0
11
- NTNlNjY5Y2ZkZmQzMWM2YjBhZWQ0ZTk4NGViMTdhMTZlZmFhYWI=
9
+ MjNiZjk0NTA3MmUxYWYxMmIwZjY4MDcyNjgwYjBlY2Y1ZmNiMTI3ZDJhOTU5
10
+ M2RjZDI2MTc3MGU4ODVmNWQ5N2ZlYzEwMGY2NzIyODc1ZjViMDM2ZTI0MTVl
11
+ NGI0OWRiODQ0ZDEwYWM1NGY4NjhiMzg1MzJlMmU4NGQwYjlhY2I=
12
12
  data.tar.gz: !binary |-
13
- ZTYzMmU1ZGZhMTRiYjY0N2ZhNDU1NTEyNTM3YmQ1MTI2ZjY3NTExYzc3Y2Vh
14
- N2Q3MDY3Zjg0YmRkNTY4YWE4NTNjYmZkMTRkMzYzODUxODkxY2VhMTAzMjk2
15
- YjcxMGYwYjBjNGE3NjFkMWNiZmM2NGM5ZjQ4Yzc3MzgxOWMyY2Q=
13
+ ZTVlYzE0YTViNjNmNDg5MTY4ODNmOTVhYTI4ZGY1NWFlZDQxYzA1MGFjMzdj
14
+ YjU4YzgxOTU2ZjYxYTcwNDVjNGM0ZDZiZDdkNzAyMzg5NDI2NzNmNTMwNDY3
15
+ OWE0YWNiMDlhZWM4MmU2MzY0MTQ1MWI0NWFlNGFkYTM1N2NiYzM=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -43,7 +43,7 @@ module Sequel
43
43
  db_schema.map do |column|
44
44
  type = parse_type(column.last[:db_type])
45
45
  DbColumn.build_from_hash(:name => column.first,
46
- :default => column.last[:ruby_default] || column.last[:default],
46
+ :default => extract_default(column),
47
47
  :null => column.last[:allow_null],
48
48
  :column_type => type,
49
49
  :unsigned => extract_unsigned(column.last[:db_type], type),
@@ -73,12 +73,21 @@ module Sequel
73
73
  case type
74
74
  when /^int/ then :integer
75
75
  when /^tinyint\(1\)/ then :boolean
76
+ when /^character varying/ then :varchar
77
+ when /^character/ then :char
78
+ when /^timestamp/ then :timestamp
79
+ when /^numeric\(\d+,\d+\)/ then :decimal
76
80
  when /^([^(]+)/ then $1.to_sym
77
81
  end
78
82
  end
79
83
 
80
84
  private
81
85
 
86
+ def extract_default(column)
87
+ default = column.last[:ruby_default] || column.last[:default]
88
+ default =~ /^"identity/ ? nil : default
89
+ end
90
+
82
91
  def extract_unsigned(db_type_string, type)
83
92
  return unless DbColumn::NUMERIC_TYPES.include?(type)
84
93
  db_type_string.include?(" unsigned")
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sequel_migration_builder 0.4.0 ruby lib
5
+ # stub: sequel_migration_builder 0.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sequel_migration_builder"
9
- s.version = "0.4.0"
9
+ s.version = "0.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Roland Swingler"]
14
- s.date = "2014-09-01"
14
+ s.date = "2014-09-02"
15
15
  s.description = "Build Sequel Migrations based on the differences between two schemas"
16
16
  s.email = "roland.swingler@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -13,7 +13,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
13
13
  a = build_column(:name => :foo, :column_type => :integer)
14
14
  b = build_column(:name => :foo, :column_type => :integer)
15
15
 
16
- @subject.build_column_operations(a,b).should == []
16
+ expect(@subject.build_column_operations(a,b)).to eql([])
17
17
  end
18
18
 
19
19
  it "should return a ChangeColumn operation if the types are different" do
@@ -21,7 +21,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
21
21
  b = build_column(:name => :foo, :column_type => :smallint)
22
22
  ops = @subject.build_column_operations(a,b)
23
23
 
24
- ops.first.should == "set_column_type :foo, :smallint, :default => nil"
24
+ expect(ops.first).to eql("set_column_type :foo, :smallint, :default => nil")
25
25
  end
26
26
 
27
27
  it "should return a ChangeColumn operation if the sizes are different" do
@@ -29,7 +29,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
29
29
  b = build_column(:name => :foo, :column_type => :char, :size => 10)
30
30
  ops = @subject.build_column_operations(a,b)
31
31
 
32
- ops.first.should == "set_column_type :foo, :char, :default => nil, :size => 10"
32
+ expect(ops.first).to eql("set_column_type :foo, :char, :default => nil, :size => 10")
33
33
  end
34
34
 
35
35
  it "should return a ChangeColumn operation if the unsigned value is different" do
@@ -37,7 +37,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
37
37
  b = build_column(:name => :foo, :column_type => :integer, :unsigned => false)
38
38
  ops = @subject.build_column_operations(a,b)
39
39
 
40
- ops.first.should == "set_column_type :foo, :integer, :default => nil, :unsigned => false"
40
+ expect(ops.first).to eql("set_column_type :foo, :integer, :default => nil, :unsigned => false")
41
41
  end
42
42
 
43
43
  it "should return a ChangeColumn operation to set the null value if the null value is different" do
@@ -45,7 +45,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
45
45
  b = build_column(:name => :foo, :column_type => :integer, :null => false)
46
46
  ops = @subject.build_column_operations(a,b)
47
47
 
48
- ops.first.should == "set_column_allow_null :foo, false"
48
+ expect(ops.first).to eql("set_column_allow_null :foo, false")
49
49
  end
50
50
 
51
51
  it "should return a ChangeColumn operation to set the default if the default value is different" do
@@ -53,7 +53,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
53
53
  b = build_column(:name => :foo, :column_type => :integer, :default => 2)
54
54
  ops = @subject.build_column_operations(a,b)
55
55
 
56
- ops.first.should == "set_column_default :foo, 2"
56
+ expect(ops.first).to eql("set_column_default :foo, 2")
57
57
  end
58
58
 
59
59
  it "should only return 1 operation if the default and other values are different" do
@@ -61,8 +61,8 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
61
61
  b = build_column(:name => :foo, :column_type => :smallint, :default => 2)
62
62
  ops = @subject.build_column_operations(a,b)
63
63
 
64
- ops.size.should == 1
65
- ops.first.should == "set_column_type :foo, :smallint, :default => 2"
64
+ expect(ops.size).to eql(1)
65
+ expect(ops.first).to eql("set_column_type :foo, :smallint, :default => 2")
66
66
  end
67
67
 
68
68
  it "should return a ChangeColumn operation if the elements are different" do
@@ -70,7 +70,7 @@ describe "Sequel::Schema::AlterTableOperations#build_column_operations" do
70
70
  b = build_column(:name => :foo, :column_type => :enum, :elements => ["A", "B"])
71
71
  ops = @subject.build_column_operations(a,b)
72
72
 
73
- ops.first.should == "set_column_type :foo, :enum, :default => nil, :elements => [\"A\", \"B\"]"
73
+ expect(ops.first).to eql("set_column_type :foo, :enum, :default => nil, :elements => [\"A\", \"B\"]")
74
74
  end
75
75
  end
76
76
 
@@ -82,7 +82,7 @@ describe "Sequel::Schema::AlterTableOperations.build" do
82
82
  :columns => [build_column(:name => :foo, :column_type => :integer)]}
83
83
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
84
84
 
85
- ops.should == []
85
+ expect(ops).to eql([])
86
86
  end
87
87
 
88
88
  it "should return an add column operation if the column is new" do
@@ -92,8 +92,8 @@ describe "Sequel::Schema::AlterTableOperations.build" do
92
92
  :columns => [build_column(:name => :foo, :column_type => :integer)]}
93
93
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
94
94
 
95
- ops.size.should == 1
96
- ops.first.should =~ /add_column/
95
+ expect(ops.size).to eql(1)
96
+ expect(ops.first).to match(/add_column/)
97
97
  end
98
98
 
99
99
  it "should return a drop column operation if the column has been removed" do
@@ -103,8 +103,8 @@ describe "Sequel::Schema::AlterTableOperations.build" do
103
103
  :columns => []}
104
104
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
105
105
 
106
- ops.size.should == 1
107
- ops.first.should =~ /drop_column/
106
+ expect(ops.size).to eql(1)
107
+ expect(ops.first).to match(/drop_column/)
108
108
  end
109
109
 
110
110
  it "should return a change column operation if columns are different" do
@@ -114,8 +114,8 @@ describe "Sequel::Schema::AlterTableOperations.build" do
114
114
  :columns => [build_column(:name => :foo, :column_type => :smallint)]}
115
115
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
116
116
 
117
- ops.size.should == 1
118
- ops.first.should =~ /set_column/
117
+ expect(ops.size).to eql(1)
118
+ expect(ops.first).to match(/set_column/)
119
119
  end
120
120
 
121
121
  it "should not output a drop index statement in #change if the index's column is also removed" do
@@ -125,7 +125,7 @@ describe "Sequel::Schema::AlterTableOperations.build" do
125
125
  table_b = {:name => :example_table, :indexes => {}, :columns => []}
126
126
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
127
127
 
128
- ops.last.should be_nil
128
+ expect(ops.last).to be_nil
129
129
  end
130
130
 
131
131
  it "should not output an add_index statement if there is nothing to be done" do
@@ -135,6 +135,6 @@ describe "Sequel::Schema::AlterTableOperations.build" do
135
135
  table_b = {:name => :example_table, :indexes => {:foo_idx => {:columns => [:foo]}}, :columns => []}
136
136
 
137
137
  ops = Sequel::Schema::AlterTableOperations.build(table_a,table_b)
138
- ops.should == []
138
+ expect(ops).to eql([])
139
139
  end
140
140
  end
@@ -7,115 +7,114 @@ describe Sequel::Schema::DbColumn do
7
7
  end
8
8
 
9
9
  it "should return a #define_statement" do
10
- @column.define_statement.should == "integer :foo, :null => false, :default => 10, :unsigned => true, :size => 10"
10
+ expect(@column.define_statement).to eql("integer :foo, :null => false, :default => 10, :unsigned => true, :size => 10")
11
11
  end
12
12
 
13
13
  it "should return a primary_key invocation if single_primary_key is set and the column is an integer" do
14
14
  @column.single_primary_key = true
15
- @column.define_statement.should == "primary_key :foo, :type => :integer, :null => false, :default => 10, :unsigned => true, :size => 10"
15
+ expect(@column.define_statement).to eql("primary_key :foo, :type => :integer, :null => false, :default => 10, :unsigned => true, :size => 10")
16
16
  end
17
17
 
18
18
  it "should return a #drop_statement" do
19
- @column.drop_statement.should == "drop_column :foo"
19
+ expect(@column.drop_statement).to eql("drop_column :foo")
20
20
  end
21
21
 
22
22
  it "should return an #add_statement" do
23
- @column.add_statement.should == "add_column :foo, :integer, :null => false, :default => 10, :unsigned => true, :size => 10"
23
+ expect(@column.add_statement).to eql("add_column :foo, :integer, :null => false, :default => 10, :unsigned => true, :size => 10")
24
24
  end
25
25
 
26
26
  it "should return a #change_null statement" do
27
- @column.change_null_statement.should == "set_column_allow_null :foo, false"
27
+ expect(@column.change_null_statement).to eql("set_column_allow_null :foo, false")
28
28
  end
29
29
 
30
30
  it "should return a #change_default statement" do
31
- @column.change_default_statement.should == "set_column_default :foo, 10"
31
+ expect(@column.change_default_statement).to eql("set_column_default :foo, 10")
32
32
  end
33
33
 
34
34
  it "should return a #change_type statement" do
35
- @column.change_type_statement.should == "set_column_type :foo, :integer, :default => 10, :unsigned => true, :size => 10"
35
+ expect(@column.change_type_statement).to eql("set_column_type :foo, :integer, :default => 10, :unsigned => true, :size => 10")
36
36
  end
37
37
 
38
38
  it "should be diffable with another DbColumn" do
39
39
  other = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 10, true, 10, nil)
40
- @column.diff(other).should == [:column_type].to_set
40
+ expect(@column.diff(other)).to eql([:column_type].to_set)
41
41
 
42
42
  other = Sequel::Schema::DbColumn.new(:foo, :integer, true, 11, true, 10, nil)
43
- @column.diff(other).should == [:null, :default].to_set
43
+ expect(@column.diff(other)).to eql([:null, :default].to_set)
44
44
  end
45
45
 
46
46
  it "should not consider allowing null being nil different from false" do
47
47
  a = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 10, true, 10, nil)
48
48
  b = Sequel::Schema::DbColumn.new(:foo, :smallint, nil, 10, true, 10, nil)
49
- a.diff(b).should be_empty
50
- b.diff(a).should be_empty
49
+ expect(a.diff(b)).to be_empty
50
+ expect(b.diff(a)).to be_empty
51
51
  end
52
52
 
53
53
  it "should not consider size to be different if one of the sizes is nil" do
54
54
  a = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 10, true, 10, nil)
55
55
  b = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 10, true, nil, nil)
56
- a.diff(b).should be_empty
57
- b.diff(a).should be_empty
56
+ expect(a.diff(b)).to be_empty
57
+ expect(b.diff(a)).to be_empty
58
58
  end
59
59
 
60
60
  it "should not consider 0 to be different from null if the column does not allow nulls" do
61
61
  a = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 0, true, 10, nil)
62
62
  b = Sequel::Schema::DbColumn.new(:foo, :smallint, false, nil, true, nil, nil)
63
- a.diff(b).should be_empty
64
- b.diff(a).should be_empty
63
+ expect(a.diff(b)).to be_empty
64
+ expect(b.diff(a)).to be_empty
65
65
  end
66
66
 
67
67
  it "should consider 0 to be different from null if the column does allow nulls" do
68
68
  a = Sequel::Schema::DbColumn.new(:foo, :smallint, true, 0, true, 10, nil)
69
69
  b = Sequel::Schema::DbColumn.new(:foo, :smallint, true, nil, true, nil, nil)
70
- a.diff(b).should == [:default].to_set
71
- b.diff(a).should == [:default].to_set
70
+ expect(a.diff(b)).to eql([:default].to_set)
71
+ expect(b.diff(a)).to eql([:default].to_set)
72
72
  end
73
73
 
74
74
  it "should consider 1 to be different from null" do
75
75
  a = Sequel::Schema::DbColumn.new(:foo, :smallint, false, 1, true, 10, nil)
76
76
  b = Sequel::Schema::DbColumn.new(:foo, :smallint, false, nil, true, nil, nil)
77
- a.diff(b).should == [:default].to_set
78
- b.diff(a).should == [:default].to_set
77
+ expect(a.diff(b)).to eql([:default].to_set)
78
+ expect(b.diff(a)).to eql([:default].to_set)
79
79
  end
80
80
 
81
81
  it "should not consider '' to be different from null if the column does not allow nulls" do
82
82
  a = Sequel::Schema::DbColumn.new(:foo, :varchar, false, '', true, 10, nil)
83
83
  b = Sequel::Schema::DbColumn.new(:foo, :varchar, false, nil, true, nil, nil)
84
- a.diff(b).should be_empty
85
- b.diff(a).should be_empty
84
+ expect(a.diff(b)).to be_empty
85
+ expect(b.diff(a)).to be_empty
86
86
  end
87
87
 
88
88
  it "should consider '' to be different from null if the column allows null" do
89
89
  a = Sequel::Schema::DbColumn.new(:foo, :varchar, true, '', true, 10, nil)
90
90
  b = Sequel::Schema::DbColumn.new(:foo, :varchar, true, nil, true, nil, nil)
91
- a.diff(b).should == [:default].to_set
92
- b.diff(a).should == [:default].to_set
91
+ expect(a.diff(b)).to eql([:default].to_set)
92
+ expect(b.diff(a)).to eql([:default].to_set)
93
93
  end
94
94
 
95
95
  it "should consider columns with different elements to be different" do
96
96
  a = Sequel::Schema::DbColumn.new(:foo, :enum, true, nil, true, nil, ["A"])
97
97
  b = Sequel::Schema::DbColumn.new(:foo, :enum, true, nil, true, nil, ["A", "B"])
98
- a.diff(b).should == [:elements].to_set
99
- b.diff(a).should == [:elements].to_set
98
+ expect(a.diff(b)).to eql([:elements].to_set)
99
+ expect(b.diff(a)).to eql([:elements].to_set)
100
100
  end
101
101
 
102
102
  it "should cast decimal defaults to the correct number" do
103
103
  a = Sequel::Schema::DbColumn.new(:foo, :decimal, true, '0.00', true, [4,2], nil)
104
104
  b = Sequel::Schema::DbColumn.new(:foo, :decimal, true, 0, true, [4,2], nil)
105
105
 
106
- a.diff(b).should == Set.new
107
- b.diff(a).should == Set.new
106
+ expect(a.diff(b)).to eql(Set.new)
107
+ expect(b.diff(a)).to eql(Set.new)
108
108
  end
109
109
 
110
110
  it "should output BigDecimal correctly in a #define_statement" do
111
- Sequel::Schema::DbColumn.new(:foo, :decimal, false, '1.1', true, [4,2], nil).
112
- define_statement.should == "decimal :foo, :null => false, :default => BigDecimal.new('1.1'), :unsigned => true, :size => [4, 2]"
111
+ expect(Sequel::Schema::DbColumn.new(:foo, :decimal, false, '1.1', true, [4,2], nil).define_statement).to eql("decimal :foo, :null => false, :default => BigDecimal.new('1.1'), :unsigned => true, :size => [4, 2]")
113
112
  end
114
113
 
115
114
  it "should be buildable from a Hash" do
116
- Sequel::Schema::DbColumn.build_from_hash(:name => "foo",
117
- :column_type => "integer").column_type.should == "integer"
118
- Sequel::Schema::DbColumn.build_from_hash('name' => "foo",
119
- 'column_type' => "integer").name.should == "foo"
115
+ expect(Sequel::Schema::DbColumn.build_from_hash(:name => "foo",
116
+ :column_type => "integer").column_type).to eql("integer")
117
+ expect(Sequel::Schema::DbColumn.build_from_hash('name' => "foo",
118
+ 'column_type' => "integer").name).to eql("foo")
120
119
  end
121
120
  end
@@ -2,79 +2,74 @@ require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
3
  describe Sequel::Schema::DbIndex do
4
4
  it "should have a name" do
5
- Sequel::Schema::DbIndex.new('foo_index', :foo).name.should == :foo_index
5
+ expect(Sequel::Schema::DbIndex.new('foo_index', :foo).name).to eql(:foo_index)
6
6
  end
7
7
 
8
8
  it "can have columns" do
9
- Sequel::Schema::DbIndex.new('foo_index', [:foo, :bar]).columns.should == [:foo, :bar]
9
+ expect(Sequel::Schema::DbIndex.new('foo_index', [:foo, :bar]).columns).to eql([:foo, :bar])
10
10
  end
11
11
 
12
12
  it "converts a single column symbol to a 1 element array of columns" do
13
- Sequel::Schema::DbIndex.new('foo_index', :foo).columns.should == [:foo]
13
+ expect(Sequel::Schema::DbIndex.new('foo_index', :foo).columns).to eql([:foo])
14
14
  end
15
15
 
16
16
  it "is not unique by default" do
17
- Sequel::Schema::DbIndex.new('foo_index', :foo).should_not be_unique
17
+ expect(Sequel::Schema::DbIndex.new('foo_index', :foo)).not_to be_unique
18
18
  end
19
19
 
20
20
  it "can be unique" do
21
- Sequel::Schema::DbIndex.new('foo_index', :foo, true).should be_unique
21
+ expect(Sequel::Schema::DbIndex.new('foo_index', :foo, true)).to be_unique
22
22
  end
23
23
 
24
24
  it "should respond to multi_column?" do
25
- Sequel::Schema::DbIndex.new('foo_index', :foo, true).should_not be_multi_column
26
- Sequel::Schema::DbIndex.new('foo_index', [:foo, :bar], true).should be_multi_column
25
+ expect(Sequel::Schema::DbIndex.new('foo_index', :foo, true)).not_to be_multi_column
26
+ expect(Sequel::Schema::DbIndex.new('foo_index', [:foo, :bar], true)).to be_multi_column
27
27
  end
28
28
 
29
29
  it "should be equal when compared with ==" do
30
30
  i1 = Sequel::Schema::DbIndex.new('foo_idx', :foo, true)
31
31
 
32
- i1.should == Sequel::Schema::DbIndex.new('foo_idx', :foo, true)
33
- i1.should == Sequel::Schema::DbIndex.new('foo_idx', [:foo], true)
34
- i1.should_not == Sequel::Schema::DbIndex.new('foo_idx', :foo, false)
35
- i1.should_not == Sequel::Schema::DbIndex.new('foo', :foo, true)
36
- i1.should_not == Sequel::Schema::DbIndex.new('foo_idx', :bar, true)
32
+ expect(i1).to eql(Sequel::Schema::DbIndex.new('foo_idx', :foo, true))
33
+ expect(i1).to eql(Sequel::Schema::DbIndex.new('foo_idx', [:foo], true))
34
+ expect(i1).to_not eql(Sequel::Schema::DbIndex.new('foo_idx', :foo, false))
35
+ expect(i1).to_not eql(Sequel::Schema::DbIndex.new('foo', :foo, true))
36
+ expect(i1).to_not eql(Sequel::Schema::DbIndex.new('foo_idx', :bar, true))
37
37
  end
38
38
 
39
39
  it "should be equal when compared with eql?" do
40
40
  i1 = Sequel::Schema::DbIndex.new('foo_idx', :foo, true)
41
41
 
42
- i1.hash.should == Sequel::Schema::DbIndex.new('foo_idx', :foo, true).hash
43
- i1.should be_eql(Sequel::Schema::DbIndex.new('foo_idx', :foo, true))
42
+ expect(i1.hash).to eql(Sequel::Schema::DbIndex.new('foo_idx', :foo, true).hash)
43
+ expect(i1).to be_eql(Sequel::Schema::DbIndex.new('foo_idx', :foo, true))
44
44
  end
45
45
 
46
46
  it "should ensure nil as unique is converted to false" do
47
- ([Sequel::Schema::DbIndex.new(:foo_idx, :foo, :unique => nil)] - [Sequel::Schema::DbIndex.new(:foo_idx, :foo, :unique => false)]).should == []
47
+ expect(([Sequel::Schema::DbIndex.new(:foo_idx, :foo, :unique => nil)] - [Sequel::Schema::DbIndex.new(:foo_idx, :foo, :unique => false)])).to eql([])
48
48
  end
49
49
 
50
50
  it "can be built from a hash returned by Sequel::Database#indexes" do
51
51
  hsh = {:foo_idx => {:columns => [:foo], :unique => true}}
52
- Sequel::Schema::DbIndex.build_from_hash(hsh).should ==
53
- [Sequel::Schema::DbIndex.new(:foo_idx, :foo, true)]
52
+ expect(Sequel::Schema::DbIndex.build_from_hash(hsh)).
53
+ to eql([Sequel::Schema::DbIndex.new(:foo_idx, :foo, true)])
54
54
  end
55
55
 
56
56
  it "should have a define statement" do
57
- Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).define_statement.should ==
58
- "index :foo, :name => :foo_idx, :unique => true"
57
+ expect(Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).define_statement).to eql("index :foo, :name => :foo_idx, :unique => true")
59
58
  end
60
59
 
61
60
  it "should have a define statement for multiple columns" do
62
- Sequel::Schema::DbIndex.new(:foo_idx, [:foo, :bar], true).define_statement.should ==
63
- "index [:foo, :bar], :name => :foo_idx, :unique => true"
61
+ expect(Sequel::Schema::DbIndex.new(:foo_idx, [:foo, :bar], true).define_statement).to eql("index [:foo, :bar], :name => :foo_idx, :unique => true")
64
62
  end
65
63
 
66
64
  it "should not output the unique value if it is false" do
67
- Sequel::Schema::DbIndex.new(:foo_idx, :foo).define_statement.should ==
68
- "index :foo, :name => :foo_idx"
65
+ expect(Sequel::Schema::DbIndex.new(:foo_idx, :foo).define_statement).to eql("index :foo, :name => :foo_idx")
69
66
  end
70
67
 
71
68
  it "should have an add_index statement" do
72
- Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).add_statement.should ==
73
- "add_index :foo, :name => :foo_idx, :unique => true"
69
+ expect(Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).add_statement).to eql("add_index :foo, :name => :foo_idx, :unique => true")
74
70
  end
75
71
 
76
72
  it "should have an drop_index statement" do
77
- Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).drop_statement.should ==
78
- "drop_index :foo, :name => :foo_idx"
73
+ expect(Sequel::Schema::DbIndex.new(:foo_idx, :foo, true).drop_statement).to eql("drop_index :foo, :name => :foo_idx")
79
74
  end
80
75
  end
@@ -2,8 +2,8 @@ require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
3
  describe "Sequel::Schema::DbSchemaParser.for_db" do
4
4
  it "should return a DbSchemaParser" do
5
- Sequel::Schema::DbSchemaParser.for_db(double(:database)).should \
6
- be_kind_of(Sequel::Schema::DbSchemaParser)
5
+ expect(Sequel::Schema::DbSchemaParser.for_db(double(:database))).
6
+ to be_kind_of(Sequel::Schema::DbSchemaParser)
7
7
  end
8
8
  end
9
9
 
@@ -20,70 +20,80 @@ describe "A hash in the array returned by Sequel::Schema::DbSchemaParser#parse_t
20
20
  end
21
21
 
22
22
  it "should contain the :name of the column" do
23
- @parser.parse_table_schema(@schema).first.name.should == :example_column
23
+ expect(@parser.parse_table_schema(@schema).first.name).to eql(:example_column)
24
24
  end
25
25
 
26
26
  it "should contain the ruby_default as the :default" do
27
- @parser.parse_table_schema(@schema).first.default.should == 1
27
+ expect(@parser.parse_table_schema(@schema).first.default).to eql(1)
28
28
  end
29
29
 
30
30
  it "should contain whether the column can be :null" do
31
- @parser.parse_table_schema(@schema).first.null.should == true
31
+ expect(@parser.parse_table_schema(@schema).first.null).to eql(true)
32
32
  end
33
33
 
34
34
  it "should contain a type of :integer given a int column" do
35
35
  set_db_type "int(11)"
36
- @parser.parse_table_schema(@schema).first.column_type.should == :integer
36
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:integer)
37
37
  end
38
38
 
39
39
  it "should contain a type of :boolean given a tinyint(1) column" do
40
40
  set_db_type "tinyint(1)"
41
- @parser.parse_table_schema(@schema).first.column_type.should == :boolean
41
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:boolean)
42
42
  end
43
43
 
44
44
  it "should contain a type of :tinyint given a tinyint column" do
45
45
  set_db_type "tinyint(4)"
46
- @parser.parse_table_schema(@schema).first.column_type.should == :tinyint
46
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:tinyint)
47
47
  end
48
48
 
49
49
  it "should contain a type of :smallint given a smallint column" do
50
50
  set_db_type "smallint(5)"
51
- @parser.parse_table_schema(@schema).first.column_type.should == :smallint
51
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:smallint)
52
52
  end
53
53
 
54
54
  it "should contain a type of :mediumint given a mediumint column" do
55
55
  set_db_type "mediumint(5)"
56
- @parser.parse_table_schema(@schema).first.column_type.should == :mediumint
56
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:mediumint)
57
57
  end
58
58
 
59
59
  it "should contain a type of :bigint given a bigint column" do
60
60
  set_db_type "bigint(10)"
61
- @parser.parse_table_schema(@schema).first.column_type.should == :bigint
61
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:bigint)
62
+ end
63
+
64
+ it "should contain a type of :decimal given a numeric(x,y) column" do
65
+ set_db_type "numeric(3,4)"
66
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:decimal)
67
+ end
68
+
69
+ it "should contain a type of :char given a character column" do
70
+ set_db_type "character(3)"
71
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:char)
62
72
  end
63
73
 
64
74
  it "should contain a :size attribute for text-like columns" do
65
75
  set_db_type "varchar(20)", :string
66
- @parser.parse_table_schema(@schema).first.size.should == 20
76
+ expect(@parser.parse_table_schema(@schema).first.size).to eql(20)
67
77
  end
68
78
 
69
79
  it "should contain a :size attribute for decimal columns" do
70
80
  set_db_type "decimal(14,5)"
71
- @parser.parse_table_schema(@schema).first.size.should == [14,5]
81
+ expect(@parser.parse_table_schema(@schema).first.size).to eql([14,5])
72
82
  end
73
83
 
74
84
  it "should contain a :size attribute for binary columns" do
75
85
  set_db_type "binary(16)", :blob
76
- @parser.parse_table_schema(@schema).first.size.should == 16
86
+ expect(@parser.parse_table_schema(@schema).first.size).to eql(16)
77
87
  end
78
88
 
79
89
  it "should contain :unsigned false if a numeric column is not unsigned" do
80
90
  set_db_type "int(10)"
81
- @parser.parse_table_schema(@schema).first.unsigned.should == false
91
+ expect(@parser.parse_table_schema(@schema).first.unsigned).to eql(false)
82
92
  end
83
93
 
84
94
  it "should contain :unsigned true if an integer column is unsigned" do
85
95
  set_db_type "int(10) unsigned"
86
- @parser.parse_table_schema(@schema).first.unsigned.should == true
96
+ expect(@parser.parse_table_schema(@schema).first.unsigned).to eql(true)
87
97
  end
88
98
 
89
99
  it "should contain :unsigned true if a decimal column is unsigned" do
@@ -95,19 +105,35 @@ describe "A hash in the array returned by Sequel::Schema::DbSchemaParser#parse_t
95
105
  :db_type => "decimal(10,2) unsigned",
96
106
  :allow_null => true }]]
97
107
 
98
- @parser.parse_table_schema(@schema).first.unsigned.should == true
108
+ expect(@parser.parse_table_schema(@schema).first.unsigned).to eql(true)
99
109
  end
100
110
 
101
111
  it "should not contain an :unsigned value if not a numeric column" do
102
112
  set_db_type "varchar(10)", :string
103
- @parser.parse_table_schema(@schema).first.unsigned.should == nil
113
+ expect(@parser.parse_table_schema(@schema).first.unsigned).to eql(nil)
104
114
  end
105
115
 
106
116
  it "should contain the elements of an enum column" do
107
117
  set_db_type "enum('foo','bar')"
108
- @parser.parse_table_schema(@schema).first.elements.should == ['foo', 'bar']
118
+ expect(@parser.parse_table_schema(@schema).first.elements).to eql(['foo', 'bar'])
109
119
  end
110
120
 
121
+ it "should be a varchar if the the db type is character varying" do
122
+ set_db_type "character varying"
123
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:varchar)
124
+ end
125
+
126
+ it "should be a timestamp if the the db type is a timestamp without time zone" do
127
+ set_db_type "timestamp without time zone"
128
+ expect(@parser.parse_table_schema(@schema).first.column_type).to eql(:timestamp)
129
+ end
130
+
131
+ it "should not have a default for postgres identity columns" do
132
+ @schema.first.last.merge!(:default => "\"identity\"(123,0)",
133
+ :ruby_default => nil)
134
+ expect(@parser.parse_table_schema(@schema).first.default).to be_nil
135
+ end
136
+
111
137
  def set_db_type(type, ruby_type=nil)
112
138
  @schema.first.last.merge!(:db_type => type)
113
139
  @schema.first.last.merge!(:type => ruby_type) if ruby_type
@@ -117,12 +143,12 @@ end
117
143
  describe "Sequel::Schema::DbSchemaParser#parse_db_schema" do
118
144
  it "should extract a list of table definitions from a database" do
119
145
  mock_db = double(:db)
120
- mock_db.should_receive(:tables).at_least(:once).and_return([:table1])
121
- mock_db.should_receive(:schema).with(:table1).and_return([])
122
- mock_db.should_receive(:indexes).with(:table1, :partial => true)
146
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([:table1])
147
+ expect(mock_db).to receive(:schema).with(:table1).and_return([])
148
+ expect(mock_db).to receive(:indexes).with(:table1, :partial => true)
123
149
 
124
150
  @parser = Sequel::Schema::DbSchemaParser.for_db(mock_db)
125
- @parser.parse_db_schema.keys.should == [:table1]
151
+ expect(@parser.parse_db_schema.keys).to eql([:table1])
126
152
  end
127
153
  end
128
154
 
@@ -139,7 +165,7 @@ describe "Parsing a text column" do
139
165
  :db_type => "text",
140
166
  :allow_null => true }]]
141
167
 
142
- lambda { parser.parse_table_schema(schema) }.should_not raise_error
168
+ expect { parser.parse_table_schema(schema) }.not_to raise_error
143
169
  end
144
170
  end
145
171
 
@@ -154,7 +180,7 @@ describe "Parsing an enum column" do
154
180
  :db_type => "enum('foo (bar)', 'baz')",
155
181
  :allow_null => true }]]
156
182
 
157
- lambda { parser.parse_table_schema(schema) }.should_not raise_error
183
+ expect { parser.parse_table_schema(schema) }.not_to raise_error
158
184
  end
159
185
 
160
186
  it "should correctly parse elements with escaped '' in them" do
@@ -168,6 +194,6 @@ describe "Parsing an enum column" do
168
194
  :allow_null => true }]]
169
195
 
170
196
 
171
- parser.parse_table_schema(schema).first.elements.should == ["don't"]
197
+ expect(parser.parse_table_schema(schema).first.elements).to eql(["don't"])
172
198
  end
173
199
  end
@@ -4,8 +4,8 @@ describe Sequel::MigrationBuilder do
4
4
 
5
5
  it "should return nil if the table hash is empty and the database has no tables" do
6
6
  mock_db = double(:database)
7
- mock_db.should_receive(:tables).at_least(:once).and_return([])
8
- Sequel::MigrationBuilder.new(mock_db).generate_migration({}).should be_nil
7
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
8
+ expect(Sequel::MigrationBuilder.new(mock_db).generate_migration({})).to be_nil
9
9
  end
10
10
 
11
11
  it "should produce a simple migration string given a database connection and a hash of tables" do
@@ -25,8 +25,8 @@ end
25
25
  END
26
26
 
27
27
  mock_db = double(:database)
28
- mock_db.should_receive(:tables).at_least(:once).and_return([])
29
- Sequel::MigrationBuilder.new(mock_db).generate_migration(tables).should == expected
28
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
29
+ expect(Sequel::MigrationBuilder.new(mock_db).generate_migration(tables)).to eql(expected)
30
30
  end
31
31
 
32
32
  it "should produce statements for multiple new tables" do
@@ -55,13 +55,13 @@ end
55
55
  END
56
56
 
57
57
  mock_db = double(:database)
58
- mock_db.should_receive(:tables).at_least(:once).and_return([])
59
- Sequel::MigrationBuilder.new(mock_db).generate_migration(tables).should == expected
58
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
59
+ expect(Sequel::MigrationBuilder.new(mock_db).generate_migration(tables)).to eql(expected)
60
60
  end
61
61
 
62
62
  it "should add the primary key of the table" do
63
63
  mock_db = double(:database)
64
- mock_db.should_receive(:tables).at_least(:once).and_return([])
64
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
65
65
  table = {
66
66
  :primary_key => :foo,
67
67
  :columns => [{:name => :foo, :column_type => :integer}, {:name => :bar, :column_type => :varchar}]
@@ -74,13 +74,12 @@ create_table :example_table do
74
74
  end
75
75
  END
76
76
 
77
- Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n").
78
- should == expected.strip
77
+ expect(Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n")).to eql(expected.strip)
79
78
  end
80
79
 
81
80
  it "should add the non-integer primary key of the table" do
82
81
  mock_db = double(:database)
83
- mock_db.should_receive(:tables).at_least(:once).and_return([])
82
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
84
83
  table = {
85
84
  :primary_key => :foo,
86
85
  :columns => [{:name => :foo, :column_type => :binary}, {:name => :bar, :column_type => :varchar}]
@@ -95,13 +94,12 @@ create_table :example_table do
95
94
  end
96
95
  END
97
96
 
98
- Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n").
99
- should == expected.strip
97
+ expect(Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n")).to eql(expected.strip)
100
98
  end
101
99
 
102
100
  it "should add the table options do the create_table statement" do
103
101
  mock_db = double(:database)
104
- mock_db.should_receive(:tables).at_least(:once).and_return([])
102
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
105
103
  table = {
106
104
  :table_options => {:engine => "myisam"},
107
105
  :columns => [{:name => :foo, :column_type => :integer}]
@@ -113,13 +111,12 @@ create_table :example_table, :engine => "myisam" do
113
111
  end
114
112
  END
115
113
 
116
- Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n").
117
- should == expected.strip
114
+ expect(Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n")).to eql(expected.strip)
118
115
  end
119
116
 
120
117
  it "should add indexes to the create_table statement" do
121
118
  mock_db = double(:database)
122
- mock_db.should_receive(:tables).at_least(:once).and_return([])
119
+ expect(mock_db).to receive(:tables).at_least(:once).and_return([])
123
120
  table = {
124
121
  :indexes => {:foo_index => {:columns => :foo, :unique => true}},
125
122
  :columns => [{:name => :foo, :column_type => :integer}]
@@ -133,8 +130,12 @@ create_table :example_table do
133
130
  end
134
131
  END
135
132
 
136
- Sequel::MigrationBuilder.new(mock_db).create_table_statement(:example_table, table).join("\n").
137
- should == expected.strip
133
+ result = Sequel::MigrationBuilder.
134
+ new(mock_db).
135
+ create_table_statement(:example_table, table).
136
+ join("\n")
137
+
138
+ expect(result).to eql(expected.strip)
138
139
  end
139
140
 
140
141
  context "when a table needs to be altered" do
@@ -144,9 +145,9 @@ END
144
145
  :columns => [{:name => :foo, :column_type => :integer}, {:name => :bar, :column_type => :varchar}]}
145
146
  }
146
147
  @mock_db = double(:database)
147
- @mock_db.should_receive(:tables).at_least(:once).and_return([:example_table])
148
- @mock_db.should_receive(:indexes).with(:example_table, :partial => true).and_return({})
149
- @mock_db.should_receive(:schema).with(:example_table).and_return([[:foo, {:type => :integer, :db_type => "smallint(5) unsigned", :allow_null => true, :ruby_default => 10}]])
148
+ expect(@mock_db).to receive(:tables).at_least(:once).and_return([:example_table])
149
+ expect(@mock_db).to receive(:indexes).with(:example_table, :partial => true).and_return({})
150
+ expect(@mock_db).to receive(:schema).with(:example_table).and_return([[:foo, {:type => :integer, :db_type => "smallint(5) unsigned", :allow_null => true, :ruby_default => 10}]])
150
151
 
151
152
  end
152
153
 
@@ -161,8 +162,7 @@ change do
161
162
  end
162
163
  end
163
164
  END
164
- Sequel::MigrationBuilder.new(@mock_db).
165
- generate_migration_body(@tables).join("\n").should == expected.strip
165
+ expect(Sequel::MigrationBuilder.new(@mock_db).generate_migration_body(@tables).join("\n")).to eql(expected.strip)
166
166
  end
167
167
 
168
168
  it "should return separate alter table statements when option is set" do
@@ -185,8 +185,7 @@ change do
185
185
  end
186
186
  end
187
187
  END
188
- Sequel::MigrationBuilder.new(@mock_db, :separate_alter_table_statements => true).
189
- generate_migration_body(@tables).join("\n").should == expected.strip
188
+ expect(Sequel::MigrationBuilder.new(@mock_db, :separate_alter_table_statements => true).generate_migration_body(@tables).join("\n")).to eql(expected.strip)
190
189
  end
191
190
 
192
191
  it "should drop and add columns instead of changing them if immutable_columns is set" do
@@ -206,21 +205,7 @@ change do
206
205
  end
207
206
  end
208
207
  END
209
- Sequel::MigrationBuilder.new(@mock_db, :separate_alter_table_statements => true, :immutable_columns => true).
210
- generate_migration_body(tables).join("\n").should == expected.strip
208
+ expect(Sequel::MigrationBuilder.new(@mock_db, :separate_alter_table_statements => true, :immutable_columns => true).generate_migration_body(tables).join("\n")).to eql(expected.strip)
211
209
  end
212
210
  end
213
-
214
- it "should drop the table if the table exists in the database but not the table hash" do
215
- pending # Deal with in a later version.
216
- mock_db = double(:database)
217
- mock_db.should_receive(:tables).at_least(:once).and_return([:example_table])
218
-
219
- expected = <<-END
220
- change do
221
- drop_table :example_table
222
- end
223
- END
224
- Sequel::MigrationBuilder.new(mock_db).generate_up({}).join("\n").should == expected
225
- end
226
211
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_migration_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roland Swingler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-01 00:00:00.000000000 Z
11
+ date: 2014-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel