bebanjo-persistize 0.0.1 → 0.0.2
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.
- data/.gitignore +2 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +35 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/persistize.gemspec +54 -0
- data/test/models/company.rb +10 -0
- data/test/models/person.rb +12 -0
- data/test/models/project.rb +9 -0
- data/test/models/task.rb +9 -0
- data/test/persistize_test.rb +101 -0
- data/test/test_helper.rb +41 -0
- metadata +22 -8
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2008 Luismi Cavallé & Sergio Gil
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
require 'rake/rdoctask'
|
|
4
|
+
|
|
5
|
+
desc 'Default: run unit tests.'
|
|
6
|
+
task :default => :test
|
|
7
|
+
|
|
8
|
+
desc 'Test the persistize plugin.'
|
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
|
10
|
+
t.libs << 'lib'
|
|
11
|
+
t.pattern = 'test/**/*_test.rb'
|
|
12
|
+
t.verbose = true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc 'Generate documentation for the persistize plugin.'
|
|
16
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
17
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
18
|
+
rdoc.title = 'Persistize'
|
|
19
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
20
|
+
rdoc.rdoc_files.include('README')
|
|
21
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
require 'jeweler'
|
|
26
|
+
Jeweler::Tasks.new do |gemspec|
|
|
27
|
+
gemspec.name = "persistize"
|
|
28
|
+
gemspec.authors = ["Sergio Gil", "Luismi Cavallé"]
|
|
29
|
+
gemspec.email = "ballsbreaking@bebanjo.com"
|
|
30
|
+
gemspec.homepage = "http://github.com/bebanjo/persistize"
|
|
31
|
+
gemspec.summary = "Easy denormalization for your ActiveRecord models"
|
|
32
|
+
gemspec.extra_rdoc_files = ["README.rdoc"]
|
|
33
|
+
end
|
|
34
|
+
rescue LoadError
|
|
35
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.2
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'persistize'
|
data/persistize.gemspec
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{persistize}
|
|
5
|
+
s.version = "0.0.2"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Sergio Gil", "Luismi Cavall\303\251"]
|
|
9
|
+
s.date = %q{2009-05-22}
|
|
10
|
+
s.email = %q{ballsbreaking@bebanjo.com}
|
|
11
|
+
s.extra_rdoc_files = [
|
|
12
|
+
"README.rdoc"
|
|
13
|
+
]
|
|
14
|
+
s.files = [
|
|
15
|
+
".gitignore",
|
|
16
|
+
"MIT-LICENSE",
|
|
17
|
+
"README.rdoc",
|
|
18
|
+
"Rakefile",
|
|
19
|
+
"VERSION",
|
|
20
|
+
"init.rb",
|
|
21
|
+
"lib/persistize.rb",
|
|
22
|
+
"persistize.gemspec",
|
|
23
|
+
"test/models/company.rb",
|
|
24
|
+
"test/models/person.rb",
|
|
25
|
+
"test/models/project.rb",
|
|
26
|
+
"test/models/task.rb",
|
|
27
|
+
"test/persistize_test.rb",
|
|
28
|
+
"test/test_helper.rb"
|
|
29
|
+
]
|
|
30
|
+
s.has_rdoc = true
|
|
31
|
+
s.homepage = %q{http://github.com/bebanjo/persistize}
|
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
33
|
+
s.require_paths = ["lib"]
|
|
34
|
+
s.rubygems_version = %q{1.3.1}
|
|
35
|
+
s.summary = %q{Easy denormalization for your ActiveRecord models}
|
|
36
|
+
s.test_files = [
|
|
37
|
+
"test/models/company.rb",
|
|
38
|
+
"test/models/person.rb",
|
|
39
|
+
"test/models/project.rb",
|
|
40
|
+
"test/models/task.rb",
|
|
41
|
+
"test/persistize_test.rb",
|
|
42
|
+
"test/test_helper.rb"
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
if s.respond_to? :specification_version then
|
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
47
|
+
s.specification_version = 2
|
|
48
|
+
|
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
50
|
+
else
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
end
|
|
54
|
+
end
|
data/test/models/task.rb
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
|
2
|
+
|
|
3
|
+
class PersistizeTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
context "Using persistize" do
|
|
6
|
+
|
|
7
|
+
setup do
|
|
8
|
+
setup_db
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
teardown do
|
|
12
|
+
drop_db
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "a person" do
|
|
16
|
+
|
|
17
|
+
setup do
|
|
18
|
+
@person = Person.create(:first_name => "Jimi", :last_name => "Hendrix")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "update the value of full name in the database when created" do
|
|
22
|
+
assert_equal('Jimi Hendrix', @person[:full_name])
|
|
23
|
+
assert_equal(@person, Person.find_by_full_name('Jimi Hendrix'))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
should "update the value of full name in the database when updated" do
|
|
27
|
+
@person.update_attributes!(:first_name => "Axl", :last_name => "Rose")
|
|
28
|
+
assert_equal('Axl Rose', @person[:full_name])
|
|
29
|
+
assert_equal(@person, Person.find_by_full_name('Axl Rose'))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should "not update the calculated value until saved" do
|
|
33
|
+
@person.first_name = 'Axl'
|
|
34
|
+
assert_equal('Jimi Hendrix', @person.full_name)
|
|
35
|
+
# TODO: Rethink this behaviour. Do we want to cache or not?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
should "call the method when reading before being created" do
|
|
39
|
+
person = Person.new(:first_name => "Jimi", :last_name => "Hendrix")
|
|
40
|
+
assert_equal('Jimi Hendrix', person.full_name)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
should "also persistize #initials" do
|
|
44
|
+
assert_equal('JH', @person[:initials])
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "a project with tasks" do
|
|
50
|
+
|
|
51
|
+
setup do
|
|
52
|
+
@project = Project.create(:name => "Rails")
|
|
53
|
+
@task = @project.tasks.create(:completed => true)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
should "update @project#completed? when a new task is created" do
|
|
57
|
+
Task.create(:project_id => @project.id, :completed => false)
|
|
58
|
+
assert !@project.reload[:completed]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
should "update @project#completed? when a task is deleted" do
|
|
62
|
+
@task.destroy
|
|
63
|
+
assert !@project.reload[:completed]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
should "update @project#completed? when a task is updated" do
|
|
67
|
+
@task.update_attributes!(:completed => false)
|
|
68
|
+
assert !@project.reload[:completed]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
should "update each task's #project_name when the project name is updated" do
|
|
72
|
+
@project.update_attributes!(:name => "Merb")
|
|
73
|
+
assert_equal "Merb", @task.reload[:project_name]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "a company with people and tasks" do
|
|
78
|
+
|
|
79
|
+
setup do
|
|
80
|
+
@company = Company.create(:name => "BeBanjo")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
should "update summary when it is created" do
|
|
84
|
+
assert_equal("BeBanjo has 0 people and 0 tasks", @company.reload[:summary])
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should "update summary when a person is created" do
|
|
88
|
+
@company.people.create(:first_name => 'Bruce', :last_name => 'Dickinson')
|
|
89
|
+
assert_equal("BeBanjo has 1 people and 0 tasks", @company.reload[:summary])
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
should "update summary when a task created" do
|
|
93
|
+
@company.tasks.create
|
|
94
|
+
assert_equal("BeBanjo has 0 people and 1 tasks", @company.reload[:summary])
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'shoulda'
|
|
4
|
+
require 'activerecord'
|
|
5
|
+
require 'activesupport'
|
|
6
|
+
require 'ruby-debug'
|
|
7
|
+
|
|
8
|
+
require File.dirname(__FILE__) + '/../init'
|
|
9
|
+
|
|
10
|
+
ActiveSupport::Dependencies.load_paths << File.dirname(__FILE__) + '/models'
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
|
13
|
+
ActiveRecord::Schema.verbose = false
|
|
14
|
+
|
|
15
|
+
def setup_db
|
|
16
|
+
ActiveRecord::Schema.define(:version => 1) do
|
|
17
|
+
create_table :people do |t|
|
|
18
|
+
t.string :first_name, :last_name, :full_name, :initials
|
|
19
|
+
t.integer :company_id
|
|
20
|
+
end
|
|
21
|
+
create_table :projects do |t|
|
|
22
|
+
t.string :name
|
|
23
|
+
t.boolean :completed
|
|
24
|
+
end
|
|
25
|
+
create_table :tasks do |t|
|
|
26
|
+
t.integer :project_id, :company_id
|
|
27
|
+
t.boolean :completed
|
|
28
|
+
t.string :project_name
|
|
29
|
+
end
|
|
30
|
+
create_table :companies do |t|
|
|
31
|
+
t.string :name, :summary
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def drop_db
|
|
37
|
+
ActiveRecord::Base.connection.tables.each do |table|
|
|
38
|
+
ActiveRecord::Base.connection.drop_table(table)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bebanjo-persistize
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Gil
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2009-05-
|
|
13
|
+
date: 2009-05-22 00:00:00 -07:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies: []
|
|
16
16
|
|
|
@@ -23,16 +23,25 @@ extensions: []
|
|
|
23
23
|
extra_rdoc_files:
|
|
24
24
|
- README.rdoc
|
|
25
25
|
files:
|
|
26
|
+
- .gitignore
|
|
27
|
+
- MIT-LICENSE
|
|
26
28
|
- README.rdoc
|
|
29
|
+
- Rakefile
|
|
30
|
+
- VERSION
|
|
31
|
+
- init.rb
|
|
27
32
|
- lib/persistize.rb
|
|
33
|
+
- persistize.gemspec
|
|
34
|
+
- test/models/company.rb
|
|
35
|
+
- test/models/person.rb
|
|
36
|
+
- test/models/project.rb
|
|
37
|
+
- test/models/task.rb
|
|
38
|
+
- test/persistize_test.rb
|
|
39
|
+
- test/test_helper.rb
|
|
28
40
|
has_rdoc: true
|
|
29
41
|
homepage: http://github.com/bebanjo/persistize
|
|
30
42
|
post_install_message:
|
|
31
43
|
rdoc_options:
|
|
32
|
-
- --
|
|
33
|
-
- --inline-source
|
|
34
|
-
- --main
|
|
35
|
-
- README.rdoc
|
|
44
|
+
- --charset=UTF-8
|
|
36
45
|
require_paths:
|
|
37
46
|
- lib
|
|
38
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
@@ -54,5 +63,10 @@ rubygems_version: 1.2.0
|
|
|
54
63
|
signing_key:
|
|
55
64
|
specification_version: 2
|
|
56
65
|
summary: Easy denormalization for your ActiveRecord models
|
|
57
|
-
test_files:
|
|
58
|
-
|
|
66
|
+
test_files:
|
|
67
|
+
- test/models/company.rb
|
|
68
|
+
- test/models/person.rb
|
|
69
|
+
- test/models/project.rb
|
|
70
|
+
- test/models/task.rb
|
|
71
|
+
- test/persistize_test.rb
|
|
72
|
+
- test/test_helper.rb
|