gigo-activerecord 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Appraisals +12 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +75 -0
- data/Rakefile +18 -0
- data/gemfiles/activerecord31.gemfile +7 -0
- data/gemfiles/activerecord31.gemfile.lock +47 -0
- data/gemfiles/activerecord32.gemfile +7 -0
- data/gemfiles/activerecord32.gemfile.lock +47 -0
- data/gemfiles/activerecord40.gemfile +7 -0
- data/gemfiles/activerecord40.gemfile.lock +59 -0
- data/gigo-activerecord.gemspec +25 -0
- data/lib/gigo-activerecord.rb +1 -0
- data/lib/gigo/active_record.rb +4 -0
- data/lib/gigo/active_record/base.rb +46 -0
- data/lib/gigo/active_record/version.rb +5 -0
- data/test/cases/all_test.rb +77 -0
- data/test/test_helper.rb +103 -0
- metadata +169 -0
data/.gitignore
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ken Collins
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# GIGO (Garbage In, Garbage Out) For ActiveRecord
|
2
|
+
|
3
|
+
See the [GIGO](http://github.com/customink/gigo) project for general information.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'gigo-activerecord'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install gigo-activerecord
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
#### Column Helpers
|
24
|
+
|
25
|
+
This gem allows you to use GIGO with ActiveRecord in a few convenient ways. First by easily declaring that a column should be loaded thru GIGO. Assuming you have a `Note` model with a `subject` column.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class Note < ActiveRecord::Base
|
29
|
+
gigo_column :subject
|
30
|
+
end
|
31
|
+
|
32
|
+
@note.subject # => "€20 – “Woohoo”"
|
33
|
+
```
|
34
|
+
|
35
|
+
GIGO extends your model in such a way that still allows you to define your own instance methods and super up thru the attribute method stack.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Note < ActiveRecord::Base
|
39
|
+
gigo_column :subject
|
40
|
+
def subject
|
41
|
+
super.upcase
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
@note.subject # => "€20 – “WOOHOO”"
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Serialized Attributes
|
49
|
+
|
50
|
+
Sometimes your serialized attributes need GIGO before loading the YAML.
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
class Order < ActiveRecord::Base
|
54
|
+
serialize :notes, Hash
|
55
|
+
gigo_serialized_attribute :notes
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
GIGO is fully tested with ActiveRecord 3.0 to 4 and upward. If you detect a problem, open up a github issue or fork the repo and help out. After you fork or clone the repository, the following commands will get you up and running on the test suite.
|
63
|
+
|
64
|
+
```shell
|
65
|
+
$ bundle install
|
66
|
+
$ bundle exec rake appraisal:setup
|
67
|
+
$ bundle exec rake appraisal test
|
68
|
+
```
|
69
|
+
|
70
|
+
We use the [appraisal](https://github.com/thoughtbot/appraisal) gem from Thoughtbot to help us generate the individual gemfiles for each ActiveSupport version and to run the tests locally against each generated Gemfile. The `rake appraisal test` command actually runs our test suite against all Rails versions in our `Appraisal` file. If you want to run the tests for a specific Rails version, use `rake -T` for a list. For example, the following command will run the tests for Rails 3.2 only.
|
71
|
+
|
72
|
+
```shell
|
73
|
+
$ bundle exec rake appraisal:activerecord32 test
|
74
|
+
```
|
75
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'appraisal'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs = ['lib','test']
|
7
|
+
t.test_files = Dir.glob('test/**/*_test.rb').sort
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
12
|
+
|
13
|
+
desc "Setup Appraisal."
|
14
|
+
task 'appraisal:setup' do
|
15
|
+
Rake::Task['appraisal:cleanup'].invoke
|
16
|
+
Rake::Task['appraisal:gemfiles'].invoke
|
17
|
+
Rake::Task['appraisal:install'].invoke
|
18
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/kencollins/Repositories/customink/gigo-activerecord
|
3
|
+
specs:
|
4
|
+
gigo-activerecord (1.0.0)
|
5
|
+
activerecord (>= 3.1)
|
6
|
+
gigo
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.1.12)
|
12
|
+
activesupport (= 3.1.12)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
i18n (~> 0.6)
|
15
|
+
activerecord (3.1.12)
|
16
|
+
activemodel (= 3.1.12)
|
17
|
+
activesupport (= 3.1.12)
|
18
|
+
arel (~> 2.2.3)
|
19
|
+
tzinfo (~> 0.3.29)
|
20
|
+
activesupport (3.1.12)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
appraisal (0.5.2)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
arel (2.2.3)
|
26
|
+
builder (3.0.4)
|
27
|
+
ensure_valid_encoding (0.5.3)
|
28
|
+
gigo (2.0.0)
|
29
|
+
activesupport (>= 3.0)
|
30
|
+
ensure_valid_encoding (~> 0.5.3)
|
31
|
+
i18n (0.6.4)
|
32
|
+
minitest (5.0.1)
|
33
|
+
multi_json (1.7.3)
|
34
|
+
rake (10.0.4)
|
35
|
+
sqlite3 (1.3.7)
|
36
|
+
tzinfo (0.3.37)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
activerecord (~> 3.1.0)
|
43
|
+
appraisal
|
44
|
+
gigo-activerecord!
|
45
|
+
minitest (~> 5.0)
|
46
|
+
rake
|
47
|
+
sqlite3
|
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: /Users/kencollins/Repositories/customink/gigo-activerecord
|
3
|
+
specs:
|
4
|
+
gigo-activerecord (1.0.0)
|
5
|
+
activerecord (>= 3.1)
|
6
|
+
gigo
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.13)
|
12
|
+
activesupport (= 3.2.13)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activerecord (3.2.13)
|
15
|
+
activemodel (= 3.2.13)
|
16
|
+
activesupport (= 3.2.13)
|
17
|
+
arel (~> 3.0.2)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.2.13)
|
20
|
+
i18n (= 0.6.1)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
appraisal (0.5.2)
|
23
|
+
bundler
|
24
|
+
rake
|
25
|
+
arel (3.0.2)
|
26
|
+
builder (3.0.4)
|
27
|
+
ensure_valid_encoding (0.5.3)
|
28
|
+
gigo (2.0.0)
|
29
|
+
activesupport (>= 3.0)
|
30
|
+
ensure_valid_encoding (~> 0.5.3)
|
31
|
+
i18n (0.6.1)
|
32
|
+
minitest (5.0.1)
|
33
|
+
multi_json (1.7.3)
|
34
|
+
rake (10.0.4)
|
35
|
+
sqlite3 (1.3.7)
|
36
|
+
tzinfo (0.3.37)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
activerecord (~> 3.2.0)
|
43
|
+
appraisal
|
44
|
+
gigo-activerecord!
|
45
|
+
minitest (~> 5.0)
|
46
|
+
rake
|
47
|
+
sqlite3
|
@@ -0,0 +1,59 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/rails/rails.git
|
3
|
+
revision: 3b266bcfeaa2268cabf4afa362ea0982b92e5b4c
|
4
|
+
specs:
|
5
|
+
activemodel (4.1.0.beta)
|
6
|
+
activesupport (= 4.1.0.beta)
|
7
|
+
builder (~> 3.1.0)
|
8
|
+
activerecord (4.1.0.beta)
|
9
|
+
activemodel (= 4.1.0.beta)
|
10
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
11
|
+
activesupport (= 4.1.0.beta)
|
12
|
+
arel (~> 4.0.0)
|
13
|
+
activesupport (4.1.0.beta)
|
14
|
+
i18n (~> 0.6, >= 0.6.4)
|
15
|
+
json (~> 1.7)
|
16
|
+
minitest (~> 5.0)
|
17
|
+
thread_safe (~> 0.1)
|
18
|
+
tzinfo (~> 0.3.37)
|
19
|
+
|
20
|
+
PATH
|
21
|
+
remote: /Users/kencollins/Repositories/customink/gigo-activerecord
|
22
|
+
specs:
|
23
|
+
gigo-activerecord (1.0.0)
|
24
|
+
activerecord (>= 3.1)
|
25
|
+
gigo
|
26
|
+
|
27
|
+
GEM
|
28
|
+
remote: https://rubygems.org/
|
29
|
+
specs:
|
30
|
+
activerecord-deprecated_finders (1.0.2)
|
31
|
+
appraisal (0.5.2)
|
32
|
+
bundler
|
33
|
+
rake
|
34
|
+
arel (4.0.0)
|
35
|
+
atomic (1.1.9)
|
36
|
+
builder (3.1.4)
|
37
|
+
ensure_valid_encoding (0.5.3)
|
38
|
+
gigo (2.0.0)
|
39
|
+
activesupport (>= 3.0)
|
40
|
+
ensure_valid_encoding (~> 0.5.3)
|
41
|
+
i18n (0.6.4)
|
42
|
+
json (1.8.0)
|
43
|
+
minitest (5.0.2)
|
44
|
+
rake (10.0.4)
|
45
|
+
sqlite3 (1.3.7)
|
46
|
+
thread_safe (0.1.0)
|
47
|
+
atomic
|
48
|
+
tzinfo (0.3.37)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
activerecord!
|
55
|
+
appraisal
|
56
|
+
gigo-activerecord!
|
57
|
+
minitest (~> 5.0)
|
58
|
+
rake
|
59
|
+
sqlite3
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gigo/active_record/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gigo-activerecord"
|
8
|
+
spec.version = GIGO::ActiveRecord::VERSION
|
9
|
+
spec.authors = ["Ken Collins"]
|
10
|
+
spec.email = ["kcollins@customink.com"]
|
11
|
+
spec.description = 'GIGO for ActiveRecord'
|
12
|
+
spec.summary = 'GIGO for ActiveRecord'
|
13
|
+
spec.homepage = 'http://github.com/customink/gigo-activerecord'
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.add_runtime_dependency 'gigo'
|
20
|
+
spec.add_runtime_dependency 'activerecord', '>= 3.1'
|
21
|
+
spec.add_development_dependency 'appraisal'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
24
|
+
spec.add_development_dependency 'sqlite3'
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'gigo/active_record'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GIGO
|
2
|
+
module ActiveRecord
|
3
|
+
module Base
|
4
|
+
|
5
|
+
def gigo_serialized_attribute(*attrs)
|
6
|
+
attrs.each do |attr|
|
7
|
+
yaml_column = self.serialized_attributes[attr.to_s]
|
8
|
+
next unless yaml_column
|
9
|
+
yaml_column.class_eval do
|
10
|
+
def load_with_gigo(yaml)
|
11
|
+
existing_encoding = Encoding.default_internal
|
12
|
+
Encoding.default_internal = GIGO.encoding
|
13
|
+
yaml = GIGO.load(yaml)
|
14
|
+
load_without_gigo(yaml)
|
15
|
+
ensure
|
16
|
+
Encoding.default_internal = existing_encoding
|
17
|
+
end
|
18
|
+
alias_method_chain :load, :gigo
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def gigo_column(*attrs)
|
24
|
+
mod = begin
|
25
|
+
if defined?(GIGOColumns)
|
26
|
+
const_get(:GIGOColumns)
|
27
|
+
else
|
28
|
+
m = const_set(:GIGOColumns, Module.new)
|
29
|
+
include m
|
30
|
+
m
|
31
|
+
end
|
32
|
+
end
|
33
|
+
attrs.each do |attr|
|
34
|
+
mod.module_eval <<-CODE, __FILE__, __LINE__
|
35
|
+
def #{attr}
|
36
|
+
GIGO.load(super)
|
37
|
+
end
|
38
|
+
CODE
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
ActiveRecord::Base.extend GIGO::ActiveRecord::Base
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module GIGO
|
5
|
+
module ActiveRecord
|
6
|
+
class AllTest < TestCase
|
7
|
+
|
8
|
+
describe 'gigo_serialized_attribute' do
|
9
|
+
|
10
|
+
before { user_data_utf8 ; user_data_cp1252 ; user_data_binary ; user_data_iso8859 }
|
11
|
+
|
12
|
+
let(:seralized_data_utf8) { with_db_encoding(utf8) { user_data_utf8.notes[:data] } }
|
13
|
+
let(:seralized_data_utf8_raw) { with_db_encoding(utf8) { UserRaw.find(user_data_utf8.id).notes } }
|
14
|
+
let(:seralized_data_utf8_gigo) { with_db_encoding(utf8) { UserGIGO.find(user_data_utf8.id).notes[:data] } }
|
15
|
+
|
16
|
+
let(:seralized_data_cp1252) { with_db_encoding(cp1252) { user_data_cp1252.notes[:data] } }
|
17
|
+
let(:seralized_data_cp1252_raw) { with_db_encoding(cp1252) { UserRaw.find(user_data_cp1252.id).notes } }
|
18
|
+
let(:seralized_data_cp1252_gigo) { with_db_encoding(cp1252) { UserGIGO.find(user_data_cp1252.id).notes[:data] } }
|
19
|
+
|
20
|
+
let(:seralized_data_binary) { with_db_encoding(binary) { user_data_binary.notes[:data] } }
|
21
|
+
let(:seralized_data_binary_raw) { with_db_encoding(binary) { UserRaw.find(user_data_binary.id).notes } }
|
22
|
+
let(:seralized_data_binary_gigo) { with_db_encoding(binary) { UserGIGO.find(user_data_binary.id).notes[:data] } }
|
23
|
+
|
24
|
+
let(:seralized_data_iso8859) { with_db_encoding(iso8859) { user_data_iso8859.notes[:data] } }
|
25
|
+
let(:seralized_data_iso8859_raw) { with_db_encoding(iso8859) { UserRaw.find(user_data_iso8859.id).notes } }
|
26
|
+
let(:seralized_data_iso8859_gigo) { with_db_encoding(iso8859) { UserGIGO.find(user_data_iso8859.id).notes[:data] } }
|
27
|
+
|
28
|
+
it 'can setup different DB data in other encodings so other test assumptions work' do
|
29
|
+
seralized_data_utf8_raw.encoding.must_equal utf8
|
30
|
+
seralized_data_cp1252_raw.encoding.must_equal cp1252
|
31
|
+
seralized_data_binary_raw.encoding.must_equal binary
|
32
|
+
seralized_data_iso8859_raw.encoding.must_equal iso8859
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can properly encode serialized data' do
|
36
|
+
seralized_data_utf8_gigo.must_equal "€20 – “Woohoo”"
|
37
|
+
seralized_data_cp1252_gigo.must_equal "€20 – “Woohoo”"
|
38
|
+
seralized_data_binary_gigo.must_equal "won’t"
|
39
|
+
seralized_data_iso8859_gigo.must_equal "Medíco"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'allows serialized attribute to still work with nil/defaults' do
|
43
|
+
user = UserGIGO.new
|
44
|
+
user.notes.must_equal Hash.new
|
45
|
+
user.save
|
46
|
+
user.reload.notes.must_equal Hash.new
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'allows serialized attribute to still work as normal' do
|
50
|
+
user = UserGIGO.new
|
51
|
+
user.notes[:foo] = 'bar'
|
52
|
+
user.save
|
53
|
+
user.reload.notes[:foo].must_equal 'bar'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'gigo_column' do
|
59
|
+
|
60
|
+
before { user_subject_binary }
|
61
|
+
|
62
|
+
let(:id) { user_subject_binary.id }
|
63
|
+
|
64
|
+
it 'hooks into GIGO' do
|
65
|
+
UserGIGO.find(id).subject.must_equal "won’t"
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'allows user to further refine #subject method via super' do
|
69
|
+
UserGIGOWithSuperSubject.find(id).subject.must_equal "WON’T"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'bundler' ; Bundler.require :development, :test
|
3
|
+
require 'gigo-activerecord'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
ActiveRecord::Base.logger = Logger.new('/dev/null')
|
8
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
|
9
|
+
|
10
|
+
module GIGO
|
11
|
+
module ActiveRecord
|
12
|
+
class TestCase < MiniTest::Spec
|
13
|
+
|
14
|
+
before { setup_schema ; setup_encodings }
|
15
|
+
|
16
|
+
let(:utf8) { Encoding::UTF_8 }
|
17
|
+
let(:cp1252) { Encoding::CP1252 }
|
18
|
+
let(:binary) { Encoding::ASCII_8BIT }
|
19
|
+
let(:iso8859) { Encoding::ISO8859_1 }
|
20
|
+
|
21
|
+
let(:data_utf8) { "€20 – “Woohoo”" }
|
22
|
+
let(:data_cp1252) { data_utf8.encode(cp1252) }
|
23
|
+
let(:data_binary) { "won\x92t".force_encoding(binary) }
|
24
|
+
let(:data_iso8859) { "Med\xEDco".force_encoding(iso8859) }
|
25
|
+
|
26
|
+
let(:user_data_utf8) {
|
27
|
+
User.create! { |u| u.notes = {data: data_utf8} }
|
28
|
+
}
|
29
|
+
let(:user_data_cp1252) {
|
30
|
+
u = User.create!
|
31
|
+
with_db_encoding(cp1252) { UserRaw.find(u.id).update_attribute :notes, "---\n:data: #{data_cp1252}\n" }
|
32
|
+
u
|
33
|
+
}
|
34
|
+
let(:user_data_binary) {
|
35
|
+
u = User.create!
|
36
|
+
with_db_encoding(binary) { UserRaw.find(u.id).update_attribute :notes, "---\n:data: #{data_binary}\n" }
|
37
|
+
u
|
38
|
+
}
|
39
|
+
let(:user_data_iso8859) {
|
40
|
+
u = User.create!
|
41
|
+
with_db_encoding(iso8859) { UserRaw.find(u.id).update_attribute :notes, "---\n:data: #{data_iso8859}\n" }
|
42
|
+
u
|
43
|
+
}
|
44
|
+
|
45
|
+
let(:user_subject_binary) {
|
46
|
+
u = User.create!
|
47
|
+
with_db_encoding(binary) { UserRaw.find(u.id).update_attribute :subject, data_binary }
|
48
|
+
u
|
49
|
+
}
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def setup_schema
|
54
|
+
::ActiveRecord::Base.class_eval do
|
55
|
+
connection.instance_eval do
|
56
|
+
create_table :users, :force => true do |t|
|
57
|
+
t.text :subject
|
58
|
+
t.text :notes
|
59
|
+
t.timestamps
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def setup_encodings
|
66
|
+
GIGO.encoding = utf8
|
67
|
+
Encoding.default_internal = utf8
|
68
|
+
end
|
69
|
+
|
70
|
+
def with_db_encoding(encoding)
|
71
|
+
Encoding.default_internal = encoding
|
72
|
+
GIGO.encoding = utf8
|
73
|
+
yield
|
74
|
+
ensure
|
75
|
+
setup_encodings
|
76
|
+
end
|
77
|
+
|
78
|
+
class User < ::ActiveRecord::Base
|
79
|
+
serialize :notes, Hash
|
80
|
+
end
|
81
|
+
|
82
|
+
class UserRaw < ::ActiveRecord::Base
|
83
|
+
self.table_name = :users
|
84
|
+
end
|
85
|
+
|
86
|
+
class UserGIGO < ::ActiveRecord::Base
|
87
|
+
self.table_name = :users
|
88
|
+
serialize :notes, Hash
|
89
|
+
gigo_serialized_attribute :notes
|
90
|
+
gigo_column :subject
|
91
|
+
end
|
92
|
+
|
93
|
+
class UserGIGOWithSuperSubject < ::ActiveRecord::Base
|
94
|
+
self.table_name = :users
|
95
|
+
gigo_column :subject
|
96
|
+
def subject
|
97
|
+
super.upcase
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gigo-activerecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ken Collins
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: gigo
|
16
|
+
type: :runtime
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
none: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
none: false
|
29
|
+
prerelease: false
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord
|
32
|
+
type: :runtime
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
38
|
+
none: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.1'
|
44
|
+
none: false
|
45
|
+
prerelease: false
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: appraisal
|
48
|
+
type: :development
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
none: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
none: false
|
61
|
+
prerelease: false
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
type: :development
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
none: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
none: false
|
77
|
+
prerelease: false
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: minitest
|
80
|
+
type: :development
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '5.0'
|
86
|
+
none: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '5.0'
|
92
|
+
none: false
|
93
|
+
prerelease: false
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sqlite3
|
96
|
+
type: :development
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
none: false
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
none: false
|
109
|
+
prerelease: false
|
110
|
+
description: GIGO for ActiveRecord
|
111
|
+
email:
|
112
|
+
- kcollins@customink.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Appraisals
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- gemfiles/activerecord31.gemfile
|
124
|
+
- gemfiles/activerecord31.gemfile.lock
|
125
|
+
- gemfiles/activerecord32.gemfile
|
126
|
+
- gemfiles/activerecord32.gemfile.lock
|
127
|
+
- gemfiles/activerecord40.gemfile
|
128
|
+
- gemfiles/activerecord40.gemfile.lock
|
129
|
+
- gigo-activerecord.gemspec
|
130
|
+
- lib/gigo-activerecord.rb
|
131
|
+
- lib/gigo/active_record.rb
|
132
|
+
- lib/gigo/active_record/base.rb
|
133
|
+
- lib/gigo/active_record/version.rb
|
134
|
+
- test/cases/all_test.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
homepage: http://github.com/customink/gigo-activerecord
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
hash: -546867824294194641
|
150
|
+
version: '0'
|
151
|
+
none: false
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: -546867824294194641
|
159
|
+
version: '0'
|
160
|
+
none: false
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 1.8.25
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: GIGO for ActiveRecord
|
167
|
+
test_files:
|
168
|
+
- test/cases/all_test.rb
|
169
|
+
- test/test_helper.rb
|