hstore-attributes 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,10 +11,10 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = "hstore-attributes"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.0.2"
15
-
14
+ gem.version = "0.0.3"
15
+
16
16
  gem.add_dependency('pg')
17
17
  gem.add_dependency('activerecord', '>= 3.0')
18
18
  gem.add_dependency('activerecord-postgres-hstore')
19
-
19
+
20
20
  end
@@ -20,6 +20,7 @@ module HstoreColumns
20
20
  module ClassMethods
21
21
 
22
22
  def hstore_accessor(hstore_column, attr_name, type = :string)
23
+ return unless table_exists?
23
24
  column = ActiveRecord::ConnectionAdapters::Column.new(attr_name, nil, "#{type}")
24
25
  columns_hash[attr_name.to_s]= column
25
26
  cast_code = column.type_cast_code('v')
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+
4
+
5
+ class EmptyDbTest < MiniTest::Unit::TestCase
6
+
7
+ def setup
8
+ @connection = ActiveRecord::Base.connection
9
+ end
10
+
11
+ describe "the hstore attribute mapper" do
12
+
13
+ it "should not break without a dabase table" do
14
+ assert_silent do
15
+
16
+ class HstoreModel < ActiveRecord::Base
17
+ hstore :data, accessors: {:color => :string, :homepage => :string, :available_on => :date}
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ class HstoreModel < ActiveRecord::Base
2
+ hstore :data, accessors: {:color => :string, :homepage => :string, :available_on => :date}
3
+ hstore :data, accessors: [:other_color, :other_homepage]
4
+
5
+ hstore :data, accessors: {:string_test => :string, :date_test => :date, :datetime_test => :datetime, :integer_test => :integer}
6
+
7
+ end
@@ -1,18 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
2
 
3
- class HstoreModel < ActiveRecord::Base
4
- hstore :data, accessors: {:color => :string, :homepage => :string, :available_on => :date}
5
- hstore :data, accessors: [:other_color, :other_homepage]
6
3
 
7
- hstore :data, accessors: {:string_test => :string, :date_test => :date, :datetime_test => :datetime, :integer_test => :integer}
8
-
9
- end
10
-
11
- class HstoreTest < MiniTest::Unit::TestCase
4
+ class HstoreTest < MiniTest::Spec
12
5
 
13
6
  def setup
14
7
  @connection = ActiveRecord::Base.connection
15
- puts @connection.native_database_types
16
8
 
17
9
  begin
18
10
  @connection.execute 'drop table if exists hstore_models'
@@ -24,25 +16,32 @@ class HstoreTest < MiniTest::Unit::TestCase
24
16
  end
25
17
 
26
18
  rescue ActiveRecord::StatementInvalid => e
27
- skip "ActiveRecord::StatementInvalid during table setup. Is your DB hstore capable at all? Error was: #{e}"
19
+ puts "--------------------------------------------------"
20
+ puts "ActiveRecord::StatementInvalid during table setup. Is your DB hstore capable at all? Error was: #{e}"
21
+ puts "--------------------------------------------------"
22
+ exit
28
23
  rescue NoMethodError => e
29
- skip "NoMethodError during table setup. Is your DB hstore capable at all? Error was: #{e}"
24
+ puts "--------------------------------------------------"
25
+ puts "NoMethodError during table setup. Is your DB hstore capable at all? Error was: #{e}"
26
+ puts "--------------------------------------------------"
27
+ exit
30
28
  end
29
+
30
+ require_relative 'hstore_model'
31
31
  end
32
32
 
33
+
33
34
  def teardown
34
35
  @connection.execute 'drop table if exists hstore_models'
35
36
  end
36
37
 
37
38
  describe "the hstore attribute mapper" do
38
39
 
40
+
39
41
  before do
40
42
  @record = HstoreModel.create(:name => 'John Doe')
41
43
  end
42
44
 
43
- after do
44
- HstoreModel.delete_all
45
- end
46
45
 
47
46
  it "should have the right column type" do
48
47
  column = HstoreModel.columns.find { |c| c.name == 'data' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hstore-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-11 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg
@@ -77,6 +77,8 @@ files:
77
77
  - lib/hstore-attributes.rb
78
78
  - lib/hstore-attributes/activerecord.rb
79
79
  - lib/hstore-attributes/hstore_columns.rb
80
+ - test/empty_db_test.rb
81
+ - test/hstore_model.rb
80
82
  - test/hstore_test.rb
81
83
  - test/test_helper.rb
82
84
  homepage: http://github.com/defsprite/hstore-attributes
@@ -93,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
95
  version: '0'
94
96
  segments:
95
97
  - 0
96
- hash: 1370101062646711657
98
+ hash: -4242591301514564069
97
99
  required_rubygems_version: !ruby/object:Gem::Requirement
98
100
  none: false
99
101
  requirements:
@@ -102,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
104
  version: '0'
103
105
  segments:
104
106
  - 0
105
- hash: 1370101062646711657
107
+ hash: -4242591301514564069
106
108
  requirements: []
107
109
  rubyforge_project:
108
110
  rubygems_version: 1.8.21
@@ -111,5 +113,7 @@ specification_version: 3
111
113
  summary: ActiveRecord meta attributes that are mapped to a single (or multiple) hstore
112
114
  columns in postgres
113
115
  test_files:
116
+ - test/empty_db_test.rb
117
+ - test/hstore_model.rb
114
118
  - test/hstore_test.rb
115
119
  - test/test_helper.rb