objectid_columns 1.0.0

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.
@@ -0,0 +1,69 @@
1
+ require 'objectid_columns'
2
+
3
+ unless defined?(VALID_OBJECTID_CLASSES)
4
+ VALID_OBJECTID_CLASSES = [ BSON::ObjectId ]
5
+ VALID_OBJECTID_CLASSES << Moped::BSON::ObjectId if defined?(Moped::BSON::ObjectId)
6
+ end
7
+
8
+ describe "Objectid extensions" do
9
+ HEX = "0123456789abcdef"
10
+
11
+ def hex(length)
12
+ out = ""
13
+ length.times { out << HEX[rand(HEX.length)] }
14
+ out
15
+ end
16
+
17
+ def binary(length)
18
+ out = ""
19
+ out.force_encoding(Encoding::BINARY) if out.respond_to?(:encoding)
20
+ length.times { out << rand(256).chr }
21
+ out
22
+ end
23
+
24
+ describe "String extensions" do
25
+ it "should raise an error on invalid cases" do
26
+ expect { "foo".to_bson_id }.to raise_error(ArgumentError)
27
+ expect { hex(23).to_bson_id }.to raise_error(ArgumentError)
28
+ expect { hex(25).to_bson_id }.to raise_error(ArgumentError)
29
+ expect { binary(11).to_bson_id }.to raise_error(ArgumentError)
30
+ expect { binary(13).to_bson_id }.to raise_error(ArgumentError)
31
+
32
+ if "".respond_to?(:encoding)
33
+ wrong_encoding = binary(12)
34
+ wrong_encoding.force_encoding(Encoding::ISO_8859_1)
35
+ expect { wrong_encoding.to_bson_id }.to raise_error(ArgumentError)
36
+ end
37
+ end
38
+ end
39
+
40
+ VALID_OBJECTID_CLASSES.each do |test_class|
41
+ context "using BSON class #{test_class.name}" do
42
+ before :each do
43
+ @tc = test_class
44
+ ObjectidColumns.preferred_bson_class = test_class
45
+ end
46
+
47
+ it "should convert Strings to the class correctly" do
48
+ h = hex(24)
49
+ h.to_bson_id.class.should == @tc
50
+ h.to_bson_id.to_s.should == h
51
+
52
+ b = binary(12)
53
+ b.to_bson_id.class.should == @tc
54
+ b.to_bson_id
55
+ end
56
+
57
+ it "should convert the class to binary correctly" do
58
+ b = binary(12)
59
+ object_id = b.to_bson_id
60
+ object_id.to_binary.should == b
61
+ end
62
+
63
+ it "should just return self for #to_bson_id" do
64
+ oid = @tc.new
65
+ oid.to_bson_id.should be(oid)
66
+ end
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: objectid_columns
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Geweke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-01-31 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: "3.0"
22
+ - - <=
23
+ - !ruby/object:Gem::Version
24
+ version: 4.99.99
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "3.0"
35
+ - - <=
36
+ - !ruby/object:Gem::Version
37
+ version: 4.99.99
38
+ type: :runtime
39
+ version_requirements: *id002
40
+ - !ruby/object:Gem::Dependency
41
+ name: bundler
42
+ prerelease: false
43
+ requirement: &id003 !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: "1.5"
48
+ type: :development
49
+ version_requirements: *id003
50
+ - !ruby/object:Gem::Dependency
51
+ name: rake
52
+ prerelease: false
53
+ requirement: &id004 !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - &id007
56
+ - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ type: :development
60
+ version_requirements: *id004
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ prerelease: false
64
+ requirement: &id005 !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: "2.14"
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: bson
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: "1.9"
79
+ type: :development
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: mysql2
83
+ prerelease: false
84
+ requirement: &id008 !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - *id007
87
+ type: :development
88
+ version_requirements: *id008
89
+ description:
90
+ email:
91
+ - ageweke@swiftype.com
92
+ executables: []
93
+
94
+ extensions: []
95
+
96
+ extra_rdoc_files: []
97
+
98
+ files:
99
+ - .gitignore
100
+ - .travis.yml
101
+ - Gemfile
102
+ - LICENSE.txt
103
+ - README.md
104
+ - Rakefile
105
+ - lib/objectid_columns.rb
106
+ - lib/objectid_columns/active_record/base.rb
107
+ - lib/objectid_columns/active_record/relation.rb
108
+ - lib/objectid_columns/dynamic_methods_module.rb
109
+ - lib/objectid_columns/extensions.rb
110
+ - lib/objectid_columns/has_objectid_columns.rb
111
+ - lib/objectid_columns/objectid_columns_manager.rb
112
+ - lib/objectid_columns/version.rb
113
+ - objectid_columns.gemspec
114
+ - spec/objectid_columns/helpers/database_helper.rb
115
+ - spec/objectid_columns/helpers/system_helpers.rb
116
+ - spec/objectid_columns/system/basic_system_spec.rb
117
+ - spec/objectid_columns/system/extensions_spec.rb
118
+ homepage: https://www.github.com/swiftype/objectid_columns
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - *id007
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - *id007
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Transparently store MongoDB ObjectId values in ActiveRecord.
141
+ test_files:
142
+ - spec/objectid_columns/helpers/database_helper.rb
143
+ - spec/objectid_columns/helpers/system_helpers.rb
144
+ - spec/objectid_columns/system/basic_system_spec.rb
145
+ - spec/objectid_columns/system/extensions_spec.rb