cerealize 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  pkg
2
2
  doc
3
3
  slide
4
+ *.rbc
5
+ Gemfile.lock
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "task"]
2
+ path = task
3
+ url = git://github.com/godfat/gemgem.git
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ script: 'git submodule update --init; bundle exec rake test'
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - ruby-head
6
+ - rbx
7
+ - rbx-2.0
8
+ - jruby
9
+ - ree
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  = cerealize changes history
2
2
 
3
+ == cerealize 1.0.0 -- 2011-06-29
4
+
5
+ * Nothing really changed, but officially support ActiveRecord 2 and 3 now.
6
+ * Added JRuby and Rubinius support.
7
+
3
8
  == cerealize 0.9.0 -- 2011-04-28
4
9
 
5
10
  * changed class_inheritable_accessor to superclass_delegating_accessor.
data/CONTRIBUTORS ADDED
@@ -0,0 +1,2 @@
1
+ Lin Jen-Shin (godfat)
2
+ Jaime Cham (jcham)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+
2
+ source 'http://rubygems.org'
3
+
4
+ gem 'activerecord'
5
+ gem 'sqlite3' , :platforms => [ :ruby]
6
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
data/README CHANGED
@@ -9,8 +9,7 @@ by Cardinal Blue ( http://cardinalblue.com )
9
9
 
10
10
  == DESCRIPTION:
11
11
 
12
- Serialize out of the Cerealize Box
13
- - a drop-in replacement for ActiveRecord's serialize
12
+ Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
14
13
 
15
14
  It can auto transcode old encoding (yaml if you're using AR's serialize),
16
15
  to new encoding (marshal, json, you name it) without any migration.
@@ -20,10 +19,6 @@ by Cardinal Blue ( http://cardinalblue.com )
20
19
  2. Marshal
21
20
  3. JSON (planned)
22
21
 
23
- Current supported ORM:
24
- 1. ActiveRecord (tested with 2.3.11)
25
- 2. DataMapper (planned)
26
-
27
22
  == SYNOPSIS:
28
23
 
29
24
  require 'cerealize'
@@ -49,8 +44,10 @@ by Cardinal Blue ( http://cardinalblue.com )
49
44
 
50
45
  == REQUIREMENTS:
51
46
 
52
- * tested with MRI 1.8.7 and 1.9.1
53
- * one of your desired ORM
47
+ * ActiveRecord 2 or 3
48
+ * Tested with MRI (official ruby) 1.9.2, 1.8.7, and trunk
49
+ * Tested with Rubinius (rbx) 1.2.3
50
+ * Tested with JRuby 1.6.2
54
51
 
55
52
  == INSTALL:
56
53
 
@@ -62,7 +59,7 @@ by Cardinal Blue ( http://cardinalblue.com )
62
59
 
63
60
  Apache License 2.0
64
61
 
65
- Copyright (c) 2010, Cardinal Blue
62
+ Copyright (c) 2010-2011, Cardinal Blue
66
63
 
67
64
  Licensed under the Apache License, Version 2.0 (the "License");
68
65
  you may not use this file except in compliance with the License.
data/README.rdoc CHANGED
@@ -9,8 +9,7 @@ by Cardinal Blue ( http://cardinalblue.com )
9
9
 
10
10
  == DESCRIPTION:
11
11
 
12
- Serialize out of the Cerealize Box
13
- - a drop-in replacement for ActiveRecord's serialize
12
+ Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
14
13
 
15
14
  It can auto transcode old encoding (yaml if you're using AR's serialize),
16
15
  to new encoding (marshal, json, you name it) without any migration.
@@ -20,10 +19,6 @@ by Cardinal Blue ( http://cardinalblue.com )
20
19
  2. Marshal
21
20
  3. JSON (planned)
22
21
 
23
- Current supported ORM:
24
- 1. ActiveRecord (tested with 2.3.11)
25
- 2. DataMapper (planned)
26
-
27
22
  == SYNOPSIS:
28
23
 
29
24
  require 'cerealize'
@@ -49,8 +44,10 @@ by Cardinal Blue ( http://cardinalblue.com )
49
44
 
50
45
  == REQUIREMENTS:
51
46
 
52
- * tested with MRI 1.8.7 and 1.9.1
53
- * one of your desired ORM
47
+ * ActiveRecord 2 or 3
48
+ * Tested with MRI (official ruby) 1.9.2, 1.8.7, and trunk
49
+ * Tested with Rubinius (rbx) 1.2.3
50
+ * Tested with JRuby 1.6.2
54
51
 
55
52
  == INSTALL:
56
53
 
@@ -62,7 +59,7 @@ by Cardinal Blue ( http://cardinalblue.com )
62
59
 
63
60
  Apache License 2.0
64
61
 
65
- Copyright (c) 2010, Cardinal Blue
62
+ Copyright (c) 2010-2011, Cardinal Blue
66
63
 
67
64
  Licensed under the Apache License, Version 2.0 (the "License");
68
65
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -11,10 +11,16 @@ task 'gem:spec' do
11
11
  require 'cerealize/version'
12
12
  s.name = 'cerealize'
13
13
  s.version = Cerealize::VERSION
14
+ s.homepage = 'https://github.com/cardinalblue/cerealize'
14
15
  # s.executables = [s.name]
15
16
 
16
- %w[activerecord].each{ |g| s.add_runtime_dependency(g, '<3') }
17
- %w[sqlite3 ].each{ |g| s.add_development_dependency(g) }
17
+ %w[activerecord].each{ |g| s.add_runtime_dependency(g) }
18
+ %w[bacon] .each{ |g| s.add_development_dependency(g) }
19
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
20
+ s.add_development_dependency('activerecord-jdbcsqlite3-adapter')
21
+ else
22
+ s.add_development_dependency('sqlite3')
23
+ end
18
24
 
19
25
  s.authors = ['Cardinal Blue', 'Lin Jen-Shin (godfat)', 'Jaime Cham']
20
26
  s.email = ['dev (XD) cardinalblue.com']
data/cerealize.gemspec CHANGED
@@ -2,35 +2,84 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cerealize}
5
- s.version = "0.9.0"
5
+ s.version = "1.0.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Cardinal Blue", "Lin Jen-Shin (godfat)", "Jaime Cham"]
9
- s.date = %q{2011-04-28}
10
- s.description = %q{Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize}
11
- s.email = ["dev (XD) cardinalblue.com"]
12
- s.extra_rdoc_files = ["CHANGES", "LICENSE", "TODO"]
13
- s.files = [".gitignore", "CHANGES", "LICENSE", "README", "README.rdoc", "Rakefile", "TODO", "bench/simple.png", "bench/simple.rb", "cerealize.gemspec", "init.rb", "lib/cerealize.rb", "lib/cerealize/attr_hash.rb", "lib/cerealize/codec/marshal.rb", "lib/cerealize/codec/text.rb", "lib/cerealize/codec/yaml.rb", "lib/cerealize/version.rb", "task/gemgem.rb", "test/common.rb", "test/real.rb", "test/stub.rb", "test/test_all_codec.rb", "test/test_attr_hash.rb", "test/test_basic.rb", "test/test_transcode.rb"]
14
- s.homepage = %q{http://github.com/godfat/}
15
- s.rdoc_options = ["--main", "README"]
16
- s.require_paths = ["lib"]
17
- s.rubygems_version = %q{1.3.7}
8
+ s.authors = [
9
+ %q{Cardinal Blue},
10
+ %q{Lin Jen-Shin (godfat)},
11
+ %q{Jaime Cham}]
12
+ s.date = %q{2011-06-29}
13
+ s.description = %q{ Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
14
+
15
+ It can auto transcode old encoding (yaml if you're using AR's serialize),
16
+ to new encoding (marshal, json, you name it) without any migration.}
17
+ s.email = [%q{dev (XD) cardinalblue.com}]
18
+ s.extra_rdoc_files = [
19
+ %q{CHANGES},
20
+ %q{CONTRIBUTORS},
21
+ %q{LICENSE},
22
+ %q{TODO}]
23
+ s.files = [
24
+ %q{.gitignore},
25
+ %q{.gitmodules},
26
+ %q{.travis.yml},
27
+ %q{CHANGES},
28
+ %q{CONTRIBUTORS},
29
+ %q{Gemfile},
30
+ %q{LICENSE},
31
+ %q{README},
32
+ %q{README.rdoc},
33
+ %q{Rakefile},
34
+ %q{TODO},
35
+ %q{bench/simple.png},
36
+ %q{bench/simple.rb},
37
+ %q{cerealize.gemspec},
38
+ %q{init.rb},
39
+ %q{lib/cerealize.rb},
40
+ %q{lib/cerealize/attr_hash.rb},
41
+ %q{lib/cerealize/codec/marshal.rb},
42
+ %q{lib/cerealize/codec/text.rb},
43
+ %q{lib/cerealize/codec/yaml.rb},
44
+ %q{lib/cerealize/version.rb},
45
+ %q{rrr.rb},
46
+ %q{task/.gitignore},
47
+ %q{task/gemgem.rb},
48
+ %q{test/common.rb},
49
+ %q{test/real.rb},
50
+ %q{test/stub.rb},
51
+ %q{test/test_all_codec.rb},
52
+ %q{test/test_attr_hash.rb},
53
+ %q{test/test_basic.rb},
54
+ %q{test/test_transcode.rb}]
55
+ s.homepage = %q{https://github.com/cardinalblue/cerealize}
56
+ s.rdoc_options = [
57
+ %q{--main},
58
+ %q{README}]
59
+ s.require_paths = [%q{lib}]
60
+ s.rubygems_version = %q{1.8.5}
18
61
  s.summary = %q{Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize}
19
- s.test_files = ["test/test_all_codec.rb", "test/test_attr_hash.rb", "test/test_basic.rb", "test/test_transcode.rb"]
62
+ s.test_files = [
63
+ %q{test/test_all_codec.rb},
64
+ %q{test/test_attr_hash.rb},
65
+ %q{test/test_basic.rb},
66
+ %q{test/test_transcode.rb}]
20
67
 
21
68
  if s.respond_to? :specification_version then
22
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
69
  s.specification_version = 3
24
70
 
25
71
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<activerecord>, ["< 3"])
72
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
73
+ s.add_development_dependency(%q<bacon>, [">= 0"])
27
74
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
28
75
  else
29
- s.add_dependency(%q<activerecord>, ["< 3"])
76
+ s.add_dependency(%q<activerecord>, [">= 0"])
77
+ s.add_dependency(%q<bacon>, [">= 0"])
30
78
  s.add_dependency(%q<sqlite3>, [">= 0"])
31
79
  end
32
80
  else
33
- s.add_dependency(%q<activerecord>, ["< 3"])
81
+ s.add_dependency(%q<activerecord>, [">= 0"])
82
+ s.add_dependency(%q<bacon>, [">= 0"])
34
83
  s.add_dependency(%q<sqlite3>, [">= 0"])
35
84
  end
36
85
  end
data/lib/cerealize.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'cerealize/attr_hash'
4
4
 
5
- gem 'activerecord', '<3'
5
+ gem 'activerecord'
6
6
  require 'active_record'
7
7
  autoload :YAML, 'yaml'
8
8
 
@@ -105,7 +105,7 @@ module Cerealize
105
105
 
106
106
  mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
107
107
  def #{field_cache}
108
- @#{property}
108
+ @#{property} ||= nil
109
109
  end
110
110
 
111
111
  def #{field_cache}=(new_value)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Cerealize
3
- VERSION = '0.9.0'
3
+ VERSION = '1.0.0'
4
4
  end
data/rrr.rb ADDED
@@ -0,0 +1,13 @@
1
+
2
+ module M
3
+ def m
4
+ 'm'
5
+ end
6
+ end
7
+
8
+ class C
9
+ extend M
10
+ end
11
+
12
+ p C.m
13
+ p C.dup.m
data/task/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.rbc
data/task/gemgem.rb CHANGED
@@ -11,13 +11,15 @@ module Gemgem
11
11
  yield(spec = Gem::Specification.new{ |s|
12
12
  s.authors = ['Lin Jen-Shin (godfat)']
13
13
  s.email = ['godfat (XD) godfat.org']
14
- s.homepage = "http://github.com/godfat/#{s.name}"
15
14
 
16
- s.summary = File.read("#{Gemgem.dir}/README").
17
- match(/DESCRIPTION:\n\n(.+?)\n\n/m)[1]
18
- s.description = s.summary
15
+ description = File.read("#{Gemgem.dir}/README").
16
+ match(/DESCRIPTION:\n\n(.+?)(?=\n\n[^\n]+:\n)/m)[1].
17
+ lines.to_a
19
18
 
20
- s.extra_rdoc_files = %w[CHANGES LICENSE TODO]
19
+ s.description = description.join
20
+ s.summary = description.first
21
+
22
+ s.extra_rdoc_files = %w[CHANGES CONTRIBUTORS LICENSE TODO]
21
23
  s.rdoc_options = %w[--main README]
22
24
  s.rubygems_version = Gem::VERSION
23
25
  s.date = Time.now.strftime('%Y-%m-%d')
@@ -25,6 +27,7 @@ module Gemgem
25
27
  s.test_files = gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
26
28
  s.require_paths = %w[lib]
27
29
  })
30
+ spec.homepage ||= "https://github.com/godfat/#{spec.name}"
28
31
  spec
29
32
  end
30
33
 
@@ -33,7 +36,18 @@ module Gemgem
33
36
  end
34
37
 
35
38
  def write
36
- File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f| f << spec.to_ruby }
39
+ File.open("#{dir}/#{spec.name}.gemspec", 'w'){ |f|
40
+ f << split_lines(spec.to_ruby) }
41
+ end
42
+
43
+ def split_lines ruby
44
+ ruby.gsub(/(.+?)\[(.+?)\]/){ |s|
45
+ if $2.index(',')
46
+ "#{$1}[\n #{$2.split(',').map(&:strip).join(",\n ")}]"
47
+ else
48
+ s
49
+ end
50
+ }
37
51
  end
38
52
 
39
53
  def all_files
@@ -130,9 +144,27 @@ end
130
144
 
131
145
  end # of gem namespace
132
146
 
133
- desc 'Run tests'
147
+ desc 'Run tests in memory'
134
148
  task :test do
135
- sh("#{Gem.ruby} -I lib -S bacon test/test_*.rb")
149
+ require 'bacon'
150
+ Bacon.extend(Bacon::TestUnitOutput)
151
+ Bacon.summary_on_exit
152
+ $LOAD_PATH.unshift('lib')
153
+ Dir['test/test_*.rb'].each{ |file| load file }
154
+ end
155
+
156
+ desc 'Run tests with shell'
157
+ task 'test:shell', :RUBY_OPTS do |t, args|
158
+ files = unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
159
+ 'test/test_*.rb'
160
+ else
161
+ Dir['test/test_*.rb'].join(' ')
162
+ end
163
+
164
+ cmd = [Gem.ruby, args[:RUBY_OPTS],
165
+ '-I', 'lib', '-S', 'bacon', '--quiet', files]
166
+
167
+ sh(cmd.compact.join(' '))
136
168
  end
137
169
 
138
170
  desc 'Generate rdoc'
@@ -148,8 +180,6 @@ task :clean => ['gem:spec'] do
148
180
  Gemgem.ignored_files.each{ |file| sh "mv #{file} #{trash}" }
149
181
  end
150
182
 
151
-
152
183
  task :default do
153
- Rake.application.options.show_task_pattern = /./
154
- Rake.application.display_tasks_and_comments
184
+ puts `#{Gem.ruby} -S #{$PROGRAM_NAME} -T`
155
185
  end
data/test/common.rb CHANGED
@@ -1,12 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'rubygems' if RUBY_VERSION < '1.9.1'
4
3
  require 'cerealize'
5
4
 
5
+ require 'bacon'
6
+
6
7
  require_relative 'stub'
7
8
  require_relative 'real'
8
9
 
9
- require 'test/unit'
10
+ Bacon.summary_on_exit
10
11
 
11
12
  def set_encoding(encoding)
12
13
  Boat.cerealize_option[:captain] = {:class => nil,
data/test/real.rb CHANGED
@@ -1,7 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
+ adapter = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
4
+ 'jdbcsqlite3'
5
+ else
6
+ 'sqlite3'
7
+ end
8
+
3
9
  ActiveRecord::Base.establish_connection(
4
- :adapter => 'sqlite3',
10
+ :adapter => adapter,
5
11
  :database => ':memory:'
6
12
  )
7
13
 
data/test/stub.rb CHANGED
@@ -10,9 +10,11 @@ class Person
10
10
  attr_accessor(*ATTR)
11
11
 
12
12
  def ==(other)
13
+ return false if other.class != self.class
13
14
  ATTR.all?{|m| send(m) == other.send(m) }
14
15
  end
15
16
  def eql?(other)
17
+ return false if other.class != self.class
16
18
  ATTR.all?{|m| send(m).eql? other.send(m) }
17
19
  end
18
20
  end
@@ -8,17 +8,14 @@ end
8
8
 
9
9
  require_relative 'common'
10
10
 
11
- class AllCodecTest < Test::Unit::TestCase
12
- def setup
11
+ describe Cerealize do
12
+ before do
13
13
  Boat.delete_all
14
14
  end
15
15
 
16
- def teardown
17
- end
18
-
19
16
  Cerealize.codec_names.each do |encoding|
20
17
 
21
- define_method "test_#{encoding}_basic" do
18
+ should "#{encoding} basic" do
22
19
  set_encoding(encoding)
23
20
 
24
21
  b = Boat.create(:name => 'pequod')
@@ -27,39 +24,39 @@ class AllCodecTest < Test::Unit::TestCase
27
24
  b.save!
28
25
 
29
26
  b = Boat.find_by_name('pequod')
30
- assert_equal Person, b.captain.class
31
- assert_equal 'ahab', b.captain.name
27
+ b.captain.class.should.equal Person
28
+ b.captain.name .should.equal 'ahab'
32
29
 
33
30
  b.captain = Person.new('ishmael') # make sure not frozen!
34
- assert_equal 'ishmael', b.captain.name
31
+ b.captain.name.should.equal 'ishmael'
35
32
  b.captain.name = 'call me ishmael'
36
33
  b.save!
37
34
 
38
35
  b = Boat.find_by_name('pequod')
39
- assert_equal 'call me ishmael', b.captain.name
36
+ b.captain.name.should.equal 'call me ishmael'
40
37
  end
41
38
 
42
39
  ['string', {:key1 => 'v', :key2 => [3,4]}].each do |captain|
43
- define_method "test_#{encoding}_for_#{captain}_changed?" do
40
+ should "#{encoding} for #{captain}_changed?" do
44
41
  b = Boat.create(:captain => captain)
45
- assert !b.changed?
42
+ b.changed?.should.equal false
46
43
  b.captain = b.captain
47
- assert !b.changed?
44
+ b.changed?.should.equal false
48
45
  b.captain = captain
49
- assert !b.changed?
46
+ b.changed?.should.equal false
50
47
  b.captain = captain.dup
51
- assert !b.changed?
48
+ b.changed?.should.equal false
52
49
  b.captain = case captain
53
50
  when String; captain.reverse
54
51
  when Hash; captain.merge(:key2 => [1,2])
55
52
  end
56
- assert b.changed?
53
+ b.changed?.should.equal true
57
54
  end
58
55
  end
59
56
 
60
57
  [ :none, :read, :read_write, :write ].each do |action|
61
58
 
62
- define_method "test_#{encoding}_partial_update_#{action}" do
59
+ should "#{encoding} partial update #{action}" do
63
60
  set_encoding(encoding)
64
61
 
65
62
  Boat.delete_all
@@ -85,39 +82,38 @@ class AllCodecTest < Test::Unit::TestCase
85
82
 
86
83
  b3 = Boat.find_by_name 'titanic'
87
84
  if [:read_write, :write].include?(action)
88
- assert_equal 'dawson', b3.captain.name
85
+ b3.captain.name.should.equal 'dawson'
89
86
  elsif action == :none
90
- assert_equal 'rose', b3.captain.name
87
+ b3.captain.name.should.equal 'rose'
91
88
  elsif action == :read
92
- assert %w{ rose dawson }.include?(b3.captain.name),
93
- "captain.name is #{b3.captain.name}"
89
+ %w{ rose dawson }.should.include?(b3.captain.name)
94
90
  end
95
91
  end
96
92
  end
97
93
 
98
- define_method "test_#{encoding}_just_save" do
94
+ should "#{encoding} just save" do
99
95
  set_encoding(encoding)
100
96
  b1 = Boat.new :name => 'alinghi'
101
97
  b1.save!
102
- assert_equal nil, Boat.find_by_name('alinghi').captain
98
+ Boat.find_by_name('alinghi').captain.should.equal nil
103
99
  end
104
100
 
105
- define_method "test_#{encoding}_just_save_writing" do
101
+ should "#{encoding} just save writing" do
106
102
  set_encoding(encoding)
107
103
  b1 = Boat.new :name => 'surprise'
108
104
  b1.captain = Person.new 'aubrey'
109
105
  b1.save!
110
- assert_equal 'aubrey', Boat.find_by_name('surprise').captain.name
106
+ Boat.find_by_name('surprise').captain.name.should.equal 'aubrey'
111
107
  end
112
108
 
113
- define_method "test_#{encoding}_just_reading" do
109
+ should "#{encoding} just reading" do
114
110
  set_encoding(encoding)
115
111
  b1 = Boat.create :name => 'black pearl', :captain => Person.new('sparrow')
116
112
  b2 = Boat.find_by_name 'black pearl'
117
- assert_equal 'sparrow', b2.captain.name
113
+ b2.captain.name.should.equal 'sparrow'
118
114
  end
119
115
 
120
- define_method "test_#{encoding}_deep_change" do
116
+ should "#{encoding} deep change" do
121
117
  set_encoding(encoding)
122
118
  b1 = Boat.create :name => 'bounty', :captain => (Person.new('bligh'))
123
119
 
@@ -125,10 +121,10 @@ class AllCodecTest < Test::Unit::TestCase
125
121
  b2.captain.hat = Hat.new('blue')
126
122
  b2.save!
127
123
 
128
- assert_equal 'blue', Boat.find_by_name('bounty').captain.hat.color
124
+ Boat.find_by_name('bounty').captain.hat.color.should.equal 'blue'
129
125
  end
130
126
 
131
- define_method "test_#{encoding}_deeper_change_object" do
127
+ should "#{encoding} deeper change object" do
132
128
  set_encoding(encoding)
133
129
  b1 = Boat.create :name => 'bounty', :captain => (Person.new('bligh'))
134
130
 
@@ -140,10 +136,10 @@ class AllCodecTest < Test::Unit::TestCase
140
136
  b2.captain.pocket << :francs
141
137
  b2.save!
142
138
 
143
- assert_equal [ :pounds, :francs ], Boat.find_by_name('bounty').captain.pocket
139
+ Boat.find_by_name('bounty').captain.pocket.should.equal [:pounds, :francs]
144
140
  end
145
141
 
146
- define_method "test_#{encoding}_deeper_change_hash" do
142
+ should "#{encoding} deeper change hash" do
147
143
  set_encoding(encoding)
148
144
  b1 = Boat.create :name => 'bounty', :captain => { :name => :bligh }
149
145
 
@@ -155,77 +151,76 @@ class AllCodecTest < Test::Unit::TestCase
155
151
  b2.captain[:pocket] << :francs
156
152
  b2.save!
157
153
 
158
- assert_equal [ :pounds, :francs ], Boat.find_by_name('bounty').captain[:pocket]
154
+ Boat.find_by_name('bounty').captain[:pocket].should.equal [:pounds, :francs]
159
155
  end
160
156
 
161
157
 
162
- define_method "test_#{encoding}_class_checking" do
158
+ should "#{encoding} class checking" do
163
159
  set_encoding(encoding)
164
160
  Boat.create :name => 'lollypop', :cargo => Blob.new
165
161
  Boat.find_by_name 'lollypop'
166
162
 
167
- Boat.create :name => 'minerva', :cargo => "WRONG KIND"
168
- assert_raise ActiveRecord::SerializationTypeMismatch do
169
- Boat.find_by_name('minerva').cargo
170
- end
163
+ lambda{
164
+ Boat.create(:name => 'minerva', :cargo => "WRONG KIND").cargo
165
+ }.should.raise ActiveRecord::SerializationTypeMismatch
171
166
  end
172
167
 
173
- define_method "test_#{encoding}_simple_hash" do
168
+ should "#{encoding} simple hash" do
174
169
  set_encoding(encoding)
175
170
  b = Boat.new
176
171
  h = { :name => 'skipper' }
177
172
  b.captain = h
178
- assert_equal h, b.captain
173
+ b.captain.should.equal h
179
174
  b.save
180
- assert_equal h, b.captain
175
+ b.captain.should.equal h
181
176
  b.captain[:actor] = 'alan hale'
182
- assert_equal 'alan hale', b.captain[:actor]
177
+ b.captain[:actor].should.equal 'alan hale'
183
178
  end
184
179
 
185
- define_method "test_#{encoding}_check_if_really_saved" do
180
+ should "#{encoding} check if really saved" do
186
181
  set_encoding(encoding)
187
182
  b = Boat.new
188
183
  b.captain = { :name => 'ramius' }
189
184
  b.save
190
185
 
191
186
  b2 = Boat.find(b.id)
192
- assert_equal b.captain, b2.captain
187
+ b2.captain.should.equal b.captain
193
188
  b2.captain[:nationality] = 'russian'
194
189
  b2.save
195
190
 
196
191
  b3 = Boat.find(b2.id)
197
- assert_equal 'russian', b3.captain[:nationality]
192
+ b3.captain[:nationality].should.equal 'russian'
198
193
  end
199
194
 
200
- define_method "test_#{encoding}_array_cerealize" do
195
+ should "#{encoding} array cerealize" do
201
196
  set_encoding(encoding)
202
197
  b = Boat.new
203
198
  b.captain = [123, 456]
204
199
  b.save
205
- assert_equal [123, 456], b.captain
206
- assert_equal [123, 456], Boat.find(b.id).captain
200
+ b.captain.should.equal [123, 456]
201
+ Boat.find(b.id).captain.should.equal [123, 456]
207
202
  end
208
203
 
209
- define_method "test_#{encoding}_repeated_saves" do
204
+ should "#{encoding} repeated saves" do
210
205
  set_encoding(encoding)
211
206
  b = Boat.new
212
207
  b.captain = { :name => 'kirk', :age => 23 }
213
208
  b.save
214
209
 
215
- assert_equal 23, b.captain[:age]
216
- assert_equal 23, Boat.first.captain[:age]
210
+ b.captain[:age].should.equal 23
211
+ Boat.first.captain[:age].should.equal 23
217
212
 
218
213
  b.captain[:age] += 1
219
214
  b.save
220
- assert_equal 24, b.captain[:age]
221
- assert_equal 24, Boat.first.captain[:age]
215
+ b.captain[:age].should.equal 24
216
+ Boat.first.captain[:age].should.equal 24
222
217
 
223
218
  b.captain[:age] += 1
224
219
  b.save
225
220
  b.captain[:age] += 1
226
221
  b.save
227
- assert_equal 26, b.captain[:age]
228
- assert_equal 26, Boat.first.captain[:age]
222
+ b.captain[:age].should.equal 26
223
+ Boat.first.captain[:age].should.equal 26
229
224
 
230
225
  b.captain[:age] += 1
231
226
  b.save
@@ -233,8 +228,8 @@ class AllCodecTest < Test::Unit::TestCase
233
228
  b.save
234
229
  b.captain[:age] += 1
235
230
  b.save
236
- assert_equal 29, b.captain[:age]
237
- assert_equal 29, Boat.first.captain[:age]
231
+ b.captain[:age].should.equal 29
232
+ Boat.first.captain[:age].should.equal 29
238
233
 
239
234
  end
240
235
  end
@@ -7,8 +7,14 @@ end
7
7
 
8
8
  require_relative 'common'
9
9
 
10
- class AttrHashTest < Test::Unit::TestCase
11
- def test_simple
10
+ describe 'attr_hash' do
11
+ def simple_case hh, ah
12
+ ah.name.should.equal hh[:name]
13
+ ah.size.should.equal hh[:size]
14
+ ah.data.should.equal hh
15
+ end
16
+
17
+ should 'simple' do
12
18
  hh = {:name => 'wane', :size => 123456}
13
19
  ah = Apple.new(hh)
14
20
 
@@ -20,29 +26,23 @@ class AttrHashTest < Test::Unit::TestCase
20
26
  simple_case(hh, ah)
21
27
  end
22
28
 
23
- def test_nil
24
- assert_nil Apple.new.name
25
- assert_nil Apple.new.data
29
+ should 'nil' do
30
+ Apple.new.name.should.equal nil
31
+ Apple.new.data.should.equal nil
26
32
  end
27
33
 
28
- def test_dont_save_twice
34
+ should 'dont save twice' do
29
35
  apple = Apple.create(:name => 'banana')
30
- assert apple.updated_at
36
+ apple.updated_at.should.not.equal nil
31
37
 
32
38
  Apple.record_timestamps = false
33
39
  apple.update_attributes(:updated_at => nil)
34
40
  Apple.record_timestamps = true
35
41
  apple2 = Apple.find(apple.id)
36
- assert_equal nil, apple2.updated_at
42
+ apple2.updated_at.should.equal nil
37
43
  apple2.update_attributes :name => 'banana'
38
- assert_equal nil, apple2.updated_at
44
+ apple2.updated_at.should.equal nil
39
45
  apple2.update_attributes :name => 'pineapple'
40
- assert apple2.updated_at
41
- end
42
-
43
- def simple_case hh, ah
44
- assert_equal hh[:name], ah.name
45
- assert_equal hh[:size], ah.size
46
- assert_equal hh , ah.data
46
+ apple2.updated_at.should.not.equal nil
47
47
  end
48
48
  end
data/test/test_basic.rb CHANGED
@@ -8,91 +8,90 @@ end
8
8
 
9
9
  require_relative 'common'
10
10
 
11
- class BasicTest < Test::Unit::TestCase
12
- def setup
11
+ describe Cerealize do
12
+ before do
13
13
  Boat.delete_all
14
14
  end
15
15
 
16
- def teardown
16
+ should 'no conflict' do
17
+ Cat.respond_to?(:captain).should.equal false
18
+ Boat.respond_to?(:food) .should.equal false
17
19
  end
18
20
 
19
- def test_no_conflict
20
- assert ! Cat.respond_to?(:captain)
21
- assert !Boat.respond_to?(:food)
22
- end
23
-
24
- def test_cerealize_module
25
- assert Cat < Cat::CerealizeMethods
26
- assert Boat < Boat::CerealizeMethods
21
+ should 'cerealize module' do
22
+ ( Cat < Cat::CerealizeMethods).should.equal true
23
+ (Boat < Boat::CerealizeMethods).should.equal true
27
24
 
28
- assert !( Cat < Boat::CerealizeMethods)
29
- assert !(Boat < Cat::CerealizeMethods)
25
+ ( Cat < Boat::CerealizeMethods).should.equal nil
26
+ (Boat < Cat::CerealizeMethods).should.equal nil
30
27
  end
31
28
 
32
- def test_super_calling
33
- assert_equal 'mood: ', Dog.new.mood
34
- assert_equal 'mood: cheerful', Dog.new(:mood => 'cheerful').mood
29
+
30
+ should 'super calling' do
31
+ Dog.new.mood .should.equal 'mood: '
32
+ Dog.new(:mood => 'cheerful').mood.should.equal 'mood: cheerful'
35
33
  end
36
34
 
37
- def test_setting_nil_in_hash
35
+ should 'setting nil in hash' do
38
36
  apple = Apple.create(:data => {:name => 'pine'})
39
- assert_equal({:name => 'pine'}, apple.data)
40
- assert_equal 'pine', apple.name
37
+ apple.data.should.equal({:name => 'pine'})
38
+ apple.name.should.equal 'pine'
41
39
  apple.data[:name] = nil
42
- assert_equal nil, apple.name
40
+ apple.name.should.equal nil
43
41
  apple.save; apple.reload
44
- assert_equal nil, apple.name
45
- assert_equal({:name => nil}, apple.data)
42
+ apple.name.should.equal nil
43
+ apple.data.should.equal({:name => nil})
46
44
  end
47
45
 
48
- def test_save_nil
46
+ should 'save nil' do
49
47
  apple = Apple.find(Apple.create(:data => [5]).id)
50
- assert_equal [5], apple.data
48
+ apple.data.should.equal [5]
51
49
  apple.update_attributes(:data => nil)
52
- assert_equal nil, apple.data
53
- assert_equal nil, Apple.find(apple.id).data
50
+ apple.data.should.equal nil
51
+ Apple.find(apple.id).data.should.equal nil
54
52
  end
55
53
 
56
- def test_encoding_yaml
54
+ should 'encoding yaml' do
57
55
  set_encoding(:yaml)
58
56
  Boat.create :name => 'yamato', :captain => Person.new('kosaku')
59
57
  s = Boat.connection.select_value("SELECT captain FROM boats WHERE name='yamato';")
60
- assert s[0..2] = '---'
58
+ s[0..2].should.equal '---'
61
59
  end
62
60
 
63
- def test_encoding_marshal
61
+ should 'encoding marshal' do
64
62
  set_encoding(:marshal)
65
63
  Boat.create :name => 'santa maria', :captain => Person.new('columbus')
66
64
  s = Boat.connection.select_value("SELECT captain FROM boats WHERE name='santa maria';")
67
- assert s[0..1] = 'BA'
65
+ s[0..1].should.equal 'BA'
68
66
  end
69
67
 
70
- def test_cerealize_option
71
- assert_equal({:name => {:class => String,
72
- :encoding => :yaml,
73
- :codec => Cerealize::Codec::Yaml},
74
-
75
- :tail => {:class => Array,
76
- :encoding => :marshal,
77
- :codec => Cerealize::Codec::Marshal,
78
- :force_encoding => true},
79
-
80
- :food => {:class => Hash,
81
- :encoding => :marshal,
82
- :codec => Cerealize::Codec::Marshal,
83
- :force_encoding => false}},
84
- Cat.cerealize_option)
68
+ should 'cerealize option' do
69
+ Cat.cerealize_option.should.equal(
70
+ {:name => {:class => String,
71
+ :encoding => :yaml,
72
+ :codec => Cerealize::Codec::Yaml},
73
+
74
+ :tail => {:class => Array,
75
+ :encoding => :marshal,
76
+ :codec => Cerealize::Codec::Marshal,
77
+ :force_encoding => true},
78
+
79
+ :food => {:class => Hash,
80
+ :encoding => :marshal,
81
+ :codec => Cerealize::Codec::Marshal,
82
+ :force_encoding => false}})
85
83
  end
86
84
 
87
- def test_inheritance
85
+ should 'inheritance' do
88
86
  mood = {:mood => {:class => String,
89
87
  :encoding => :marshal,
90
88
  :codec => Cerealize::Codec::Marshal}}
91
89
  hook = {:hook => {:class => Integer,
92
90
  :encoding => :marshal,
93
91
  :codec => Cerealize::Codec::Marshal}}
94
- assert_equal(mood.merge(hook), Dog.cerealize_option)
95
- assert_equal(mood.merge(hook), BigDog.cerealize_option)
92
+ Dog.cerealize_option.should.equal mood.merge(hook)
93
+ BigDog.cerealize_option.should.equal mood.merge(hook)
96
94
  end
97
95
 
96
+
98
97
  end
@@ -8,31 +8,26 @@ end
8
8
 
9
9
  require_relative 'common'
10
10
 
11
- class TranscodeTest < Test::Unit::TestCase
12
- def setup
11
+ describe Cerealize do
12
+ before do
13
13
  Cat.delete_all
14
14
  end
15
15
 
16
- def teardown
17
- end
18
-
19
- def test_no_such_codec
20
- assert_raise Cerealize::NoSuchCodec do
16
+ should 'no such codec' do
17
+ lambda{
21
18
  Cat.dup.send(:cerealize, :bad, Hash, :encoding => :blah)
22
- end
19
+ }.should.raise(Cerealize::NoSuchCodec)
23
20
  end
24
21
 
25
- def test_no_suitable_codec_if_force_encoding
22
+ should 'no suitable codec if force encoding' do
26
23
  cat = Cat.new
27
24
  cat[:tail] = '---'
28
- cat.save
29
- id = cat.id
30
- assert_raise Cerealize::NoSuitableCodec do
31
- Cat.find(id).tail
32
- end
25
+ lambda{
26
+ cat.tail
27
+ }.should.raise(Cerealize::NoSuitableCodec)
33
28
  end
34
29
 
35
- def test_auto_transcode_yaml
30
+ should 'auto transcode yaml' do
36
31
  name = 'Nine Tails'
37
32
  marshaled_name = Cerealize::Codec::Marshal.encode(name)
38
33
  cat = Cat.new
@@ -41,20 +36,20 @@ class TranscodeTest < Test::Unit::TestCase
41
36
  id = cat.id
42
37
 
43
38
  new_cat = Cat.find(id)
44
- assert_equal name, new_cat.name
39
+ new_cat.name.should.equal name
45
40
  new_cat.name.reverse!
46
41
 
47
42
  # no change if not saved yet
48
- assert_equal marshaled_name, new_cat[:name]
43
+ new_cat[:name].should.equal marshaled_name
49
44
  new_cat.save
50
45
 
51
46
  # should be transcode into YAML
52
- assert Cerealize::Codec::Yaml.yours?(new_cat[:name])
47
+ Cerealize::Codec::Yaml.yours?(new_cat[:name]).should.equal true
53
48
  new_cat.reload
54
- assert Cerealize::Codec::Yaml.yours?(new_cat[:name])
49
+ Cerealize::Codec::Yaml.yours?(new_cat[:name]).should.equal true
55
50
  end
56
51
 
57
- def test_auto_transcode_marshal
52
+ should 'auto transcode marshal' do
58
53
  food = {:a => :b}
59
54
  yamled_food = Cerealize::Codec::Yaml.encode(food)
60
55
  cat = Cat.new
@@ -62,13 +57,13 @@ class TranscodeTest < Test::Unit::TestCase
62
57
  cat.save
63
58
  cat.reload
64
59
 
65
- assert_equal food, cat.food
66
- assert_equal yamled_food, cat[:food]
60
+ cat .food .should.equal food
61
+ cat[:food].should.equal yamled_food
67
62
  cat.food.merge!(:c => :d)
68
63
  cat.save
69
64
  cat.reload
70
65
 
71
- assert Cerealize::Codec::Marshal.yours?(cat[:food])
72
- assert_equal food.merge(:c => :d), cat.food
66
+ Cerealize::Codec::Marshal.yours?(cat[:food]).should.equal true
67
+ cat.food.should.equal food.merge(:c => :d)
73
68
  end
74
69
  end
metadata CHANGED
@@ -1,64 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cerealize
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 0
9
- version: 0.9.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Cardinal Blue
13
9
  - Lin Jen-Shin (godfat)
14
10
  - Jaime Cham
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2011-04-28 00:00:00 +08:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
14
+ date: 2011-06-29 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
23
17
  name: activerecord
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &2152593320 !ruby/object:Gem::Requirement
26
19
  none: false
27
- requirements:
28
- - - <
29
- - !ruby/object:Gem::Version
30
- segments:
31
- - 3
32
- version: "3"
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
33
24
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: sqlite3
37
25
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *2152593320
27
+ - !ruby/object:Gem::Dependency
28
+ name: bacon
29
+ requirement: &2152592600 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *2152592600
38
+ - !ruby/object:Gem::Dependency
39
+ name: sqlite3
40
+ requirement: &2152591980 !ruby/object:Gem::Requirement
39
41
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
46
  type: :development
47
- version_requirements: *id002
48
- description: Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
49
- email:
47
+ prerelease: false
48
+ version_requirements: *2152591980
49
+ description: ! " Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's
50
+ serialize\n\n It can auto transcode old encoding (yaml if you're using AR's serialize),\n
51
+ to new encoding (marshal, json, you name it) without any migration."
52
+ email:
50
53
  - dev (XD) cardinalblue.com
51
54
  executables: []
52
-
53
55
  extensions: []
54
-
55
- extra_rdoc_files:
56
+ extra_rdoc_files:
56
57
  - CHANGES
58
+ - CONTRIBUTORS
57
59
  - LICENSE
58
60
  - TODO
59
- files:
61
+ files:
60
62
  - .gitignore
63
+ - .gitmodules
64
+ - .travis.yml
61
65
  - CHANGES
66
+ - CONTRIBUTORS
67
+ - Gemfile
62
68
  - LICENSE
63
69
  - README
64
70
  - README.rdoc
@@ -74,6 +80,8 @@ files:
74
80
  - lib/cerealize/codec/text.rb
75
81
  - lib/cerealize/codec/yaml.rb
76
82
  - lib/cerealize/version.rb
83
+ - rrr.rb
84
+ - task/.gitignore
77
85
  - task/gemgem.rb
78
86
  - test/common.rb
79
87
  - test/real.rb
@@ -82,40 +90,34 @@ files:
82
90
  - test/test_attr_hash.rb
83
91
  - test/test_basic.rb
84
92
  - test/test_transcode.rb
85
- has_rdoc: true
86
- homepage: http://github.com/godfat/
93
+ homepage: https://github.com/cardinalblue/cerealize
87
94
  licenses: []
88
-
89
95
  post_install_message:
90
- rdoc_options:
96
+ rdoc_options:
91
97
  - --main
92
98
  - README
93
- require_paths:
99
+ require_paths:
94
100
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
101
+ required_ruby_version: !ruby/object:Gem::Requirement
96
102
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
- version: "0"
103
- required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
108
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- segments:
109
- - 0
110
- version: "0"
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
111
113
  requirements: []
112
-
113
114
  rubyforge_project:
114
- rubygems_version: 1.3.7
115
+ rubygems_version: 1.8.5
115
116
  signing_key:
116
117
  specification_version: 3
117
- summary: Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's serialize
118
- test_files:
118
+ summary: Serialize out of the Cerealize Box - a drop-in replacement for ActiveRecord's
119
+ serialize
120
+ test_files:
119
121
  - test/test_all_codec.rb
120
122
  - test/test_attr_hash.rb
121
123
  - test/test_basic.rb