schema_plus 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -176,6 +176,7 @@ take advantage of auto-creation of foreign keys, you can re-enable it:
176
176
  == History
177
177
 
178
178
  * Recent Release notes:
179
+ * 0.3.4 - bug fix: regression causing :default => false to be ignored
179
180
  * 0.3.3 - bug fix: properly handle boolean defaults in mysql
180
181
  * 0.3.2 - bug fix: make sure rake db:schema:load initializes schema_plus
181
182
  * 0.3.1 - bug fix for PostgreSQL schema dump after change_column_default(... nil)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/ronen/github/schema_plus
3
3
  specs:
4
- schema_plus (0.3.3)
4
+ schema_plus (0.3.4)
5
5
  rails
6
6
  valuable
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/ronen/github/schema_plus
3
3
  specs:
4
- schema_plus (0.3.3)
4
+ schema_plus (0.3.4)
5
5
  rails
6
6
  valuable
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/ronen/github/schema_plus
3
3
  specs:
4
- schema_plus (0.3.3)
4
+ schema_plus (0.3.4)
5
5
  rails
6
6
  valuable
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/ronen/github/schema_plus
3
3
  specs:
4
- schema_plus (0.3.3)
4
+ schema_plus (0.3.4)
5
5
  rails
6
6
  valuable
7
7
 
@@ -135,7 +135,7 @@ module SchemaPlus
135
135
  raise ArgumentError, "Invalid default expression" unless default_expr_valid?(expr)
136
136
  sql << " DEFAULT #{expr}"
137
137
  else
138
- sql << " DEFAULT #{quote(value, options[:column])}" if value
138
+ sql << " DEFAULT #{quote(value, options[:column])}" unless value.nil?
139
139
  end
140
140
  end
141
141
  # must explicitly check for :null to allow change_column to work on migrations
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -8,96 +8,127 @@ describe "Column definition" do
8
8
 
9
9
  let(:connection) { ActiveRecord::Base.connection }
10
10
 
11
- before(:each) do
12
- @sql = 'time_taken text'
13
- end
14
-
15
- context "just default passed" do
11
+ context "text columns" do
16
12
  before(:each) do
17
- connection.add_column_options!(@sql, { :default => "2011-12-11 00:00:00" })
13
+ @sql = 'time_taken text'
18
14
  end
19
15
 
20
- subject { @sql}
16
+ context "just default passed" do
17
+ before(:each) do
18
+ connection.add_column_options!(@sql, { :default => "2011-12-11 00:00:00" })
19
+ end
20
+
21
+ subject { @sql}
21
22
 
22
- it "should use the normal default" do
23
- should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
23
+ it "should use the normal default" do
24
+ should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
25
+ end
24
26
  end
25
27
 
26
- end
28
+ context "just default passed in hash" do
29
+ before(:each) do
30
+ connection.add_column_options!(@sql, { :default => { :value => "2011-12-11 00:00:00" } })
31
+ end
27
32
 
28
- context "just default passed in hash" do
29
- before(:each) do
30
- connection.add_column_options!(@sql, { :default => { :value => "2011-12-11 00:00:00" } })
33
+ subject { @sql}
34
+
35
+ it "should use the normal default" do
36
+ should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
37
+ end
31
38
  end
32
39
 
33
- subject { @sql}
40
+ context "default function passed as now" do
41
+ before(:each) do
42
+ begin
43
+ connection.add_column_options!(@sql, { :default => :now })
44
+ rescue ArgumentError => e
45
+ @raised_argument_error = e
46
+ end
47
+ end
34
48
 
35
- it "should use the normal default" do
36
- should == "time_taken text DEFAULT '2011-12-11 00:00:00'"
37
- end
38
- end
49
+ subject { @sql }
39
50
 
40
- context "default function passed as now" do
41
- before(:each) do
42
- begin
43
- connection.add_column_options!(@sql, { :default => :now })
44
- rescue ArgumentError => e
45
- @raised_argument_error = e
51
+ if SchemaPlusHelpers.postgresql?
52
+ it "should use NOW() as the default" do
53
+ should == "time_taken text DEFAULT NOW()"
54
+ end
46
55
  end
47
- end
48
56
 
49
- subject { @sql }
57
+ if SchemaPlusHelpers.sqlite3?
58
+ it "should use NOW() as the default" do
59
+ should == "time_taken text DEFAULT (DATETIME('now'))"
60
+ end
61
+ end
50
62
 
51
- if SchemaPlusHelpers.postgresql?
52
- it "should use NOW() as the default" do
53
- should == "time_taken text DEFAULT NOW()"
63
+ if SchemaPlusHelpers.mysql?
64
+ it "should raise an error" do
65
+ @raised_argument_error.should be_a ArgumentError
66
+ end
54
67
  end
55
68
  end
56
69
 
57
- if SchemaPlusHelpers.sqlite3?
58
- it "should use NOW() as the default" do
59
- should == "time_taken text DEFAULT (DATETIME('now'))"
70
+ context "valid expr passed as default" do
71
+ subject { connection.add_column_options!(@sql, { :default => { :expr => 'NOW()' } }); @sql }
72
+
73
+ if SchemaPlusHelpers.postgresql?
74
+ it "should use NOW() as the default" do
75
+ should == "time_taken text DEFAULT NOW()"
76
+ end
77
+ end
78
+
79
+ if SchemaPlusHelpers.sqlite3?
80
+ it "should use NOW() as the default" do
81
+ should == "time_taken text DEFAULT NOW()"
82
+ end
83
+ end
84
+
85
+ if SchemaPlusHelpers.mysql?
86
+ it "should raise an error" do
87
+ lambda { subject }.should raise_error
88
+ end
60
89
  end
61
90
  end
62
91
 
63
- if SchemaPlusHelpers.mysql?
64
- it "should raise an error" do
65
- @raised_argument_error.should be_a ArgumentError
92
+ context "invalid expr passed as default" do
93
+ if SchemaPlusHelpers.mysql?
94
+ it "should raise an error" do
95
+ lambda {connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })}.should raise_error ArgumentError
96
+ end
97
+ else
98
+ it "should just accept the SQL" do
99
+ connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })
100
+ @sql.should == "time_taken text DEFAULT ARBITRARY_EXPR"
101
+ end
66
102
  end
67
103
  end
68
104
  end
69
105
 
70
- context "valid expr passed as default" do
71
- subject { connection.add_column_options!(@sql, { :default => { :expr => 'NOW()' } }); @sql }
72
-
73
- if SchemaPlusHelpers.postgresql?
74
- it "should use NOW() as the default" do
75
- should == "time_taken text DEFAULT NOW()"
76
- end
106
+ context "boolean column" do
107
+ before(:each) do
108
+ @sql = 'time_taken boolean'
77
109
  end
78
110
 
79
- if SchemaPlusHelpers.sqlite3?
80
- it "should use NOW() as the default" do
81
- should == "time_taken text DEFAULT NOW()"
111
+ context "passed as boolean false" do
112
+ before(:each) do
113
+ connection.add_column_options!(@sql, { :default => false })
82
114
  end
83
- end
84
115
 
85
- if SchemaPlusHelpers.mysql?
86
- it "should raise an error" do
87
- lambda { subject }.should raise_error
116
+ subject { @sql}
117
+
118
+ it "should give the default as false" do
119
+ should match /boolean DEFAULT (\'f\'|0)/
88
120
  end
89
121
  end
90
- end
91
122
 
92
- context "invalid expr passed as default" do
93
- if SchemaPlusHelpers.mysql?
94
- it "should raise an error" do
95
- lambda {connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })}.should raise_error ArgumentError
123
+ context "passed as boolean true" do
124
+ before(:each) do
125
+ connection.add_column_options!(@sql, { :default => true })
96
126
  end
97
- else
98
- it "should just accept the SQL" do
99
- connection.add_column_options!(@sql, { :default => { :expr => "ARBITRARY_EXPR" } })
100
- @sql.should == "time_taken text DEFAULT ARBITRARY_EXPR"
127
+
128
+ subject { @sql}
129
+
130
+ it "should give the default as true" do
131
+ should match /boolean DEFAULT (\'t\'|1)/
101
132
  end
102
133
  end
103
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-24 00:00:00.000000000 Z
13
+ date: 2012-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &70124822121760 !ruby/object:Gem::Requirement
17
+ requirement: &70148459617200 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70124822121760
25
+ version_requirements: *70148459617200
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: valuable
28
- requirement: &70124822121340 !ruby/object:Gem::Requirement
28
+ requirement: &70148459616780 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70124822121340
36
+ version_requirements: *70148459616780
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &70124822120840 !ruby/object:Gem::Requirement
39
+ requirement: &70148459616280 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.8.7
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70124822120840
47
+ version_requirements: *70148459616280
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70124822120420 !ruby/object:Gem::Requirement
50
+ requirement: &70148459615860 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70124822120420
58
+ version_requirements: *70148459615860
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: pg
61
- requirement: &70124822119960 !ruby/object:Gem::Requirement
61
+ requirement: &70148459615400 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70124822119960
69
+ version_requirements: *70148459615400
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: mysql
72
- requirement: &70124822119540 !ruby/object:Gem::Requirement
72
+ requirement: &70148459614980 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70124822119540
80
+ version_requirements: *70148459614980
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: sqlite3
83
- requirement: &70124822119120 !ruby/object:Gem::Requirement
83
+ requirement: &70148459614560 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70124822119120
91
+ version_requirements: *70148459614560
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: simplecov
94
- requirement: &70124822118700 !ruby/object:Gem::Requirement
94
+ requirement: &70148459614140 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *70124822118700
102
+ version_requirements: *70148459614140
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: simplecov-gem-adapter
105
- requirement: &70124822118280 !ruby/object:Gem::Requirement
105
+ requirement: &70148459613720 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,7 +110,7 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *70124822118280
113
+ version_requirements: *70148459613720
114
114
  description: ! 'SchemaPlus is an ActiveRecord extension that provides enhanced capabilities
115
115
  for schema definition and querying, including: enhanced and more DRY index capabilities,
116
116
  support and automation for foreign key constraints, and support for views.'