persistize 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,35 +1,69 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rake/rdoctask'
1
+ require "rubygems"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
4
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'
5
+ require "rake/testtask"
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/*_test.rb"]
12
9
  t.verbose = true
13
10
  end
14
11
 
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')
12
+ task :default => ["test"]
13
+
14
+ spec = Gem::Specification.new do |s|
15
+
16
+ # Change these as appropriate
17
+ s.name = "persistize"
18
+ s.version = "0.1.1"
19
+ s.summary = "Easy denormalization for your ActiveRecord models"
20
+ s.authors = ["Sergio Gil", "Luismi Cavallé"]
21
+ s.email = "ballsbreaking@bebanjo.com"
22
+ s.homepage = "http://githum.com/bebanjo/persistize"
23
+
24
+ s.has_rdoc = true
25
+ s.extra_rdoc_files = %w(README.rdoc)
26
+ s.rdoc_options = %w(--main README.rdoc)
27
+
28
+ # Add any extra files to include in the gem
29
+ s.files = %w(init.rb MIT-LICENSE persistize.gemspec Rakefile README.rdoc VERSION) + Dir.glob("{test,lib/**/*}")
30
+ s.require_paths = ["lib"]
31
+
32
+ # If you want to depend on other gems, add them here, along with any
33
+ # relevant versions
34
+ # s.add_dependency("some_other_gem", "~> 0.1.0")
35
+
36
+ # If your tests use any gems, include them here
37
+ # s.add_development_dependency("mocha") # for example
22
38
  end
23
39
 
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
40
+ # This task actually builds the gem. We also regenerate a static
41
+ # .gemspec file, which is useful if something (i.e. GitHub) will
42
+ # be automatically building a gem for this project. If you're not
43
+ # using GitHub, edit as appropriate.
44
+ #
45
+ # To publish your gem online, install the 'gemcutter' gem; Read more
46
+ # about that here: http://gemcutter.org/pages/gem_docs
47
+ Rake::GemPackageTask.new(spec) do |pkg|
48
+ pkg.gem_spec = spec
49
+ end
50
+
51
+ desc "Build the gemspec file #{spec.name}.gemspec"
52
+ task :gemspec do
53
+ file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
54
+ File.open(file, "w") {|f| f << spec.to_ruby }
55
+ end
56
+
57
+ task :package => :gemspec
58
+
59
+ # Generate documentation
60
+ Rake::RDocTask.new do |rd|
61
+ rd.main = "README.rdoc"
62
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
63
+ rd.rdoc_dir = "rdoc"
64
+ end
65
+
66
+ desc 'Clear out RDoc and generated packages'
67
+ task :clean => [:clobber_rdoc, :clobber_package] do
68
+ rm "#{spec.name}.gemspec"
69
+ end
data/lib/persistize.rb CHANGED
@@ -20,7 +20,7 @@ module Persistize
20
20
  end # end
21
21
  end # end
22
22
  #
23
- before_save :#{update_method} # before_save :_update_full_name
23
+ before_save :#{update_method}, :if => :changed? # before_save :_update_full_name
24
24
  #
25
25
  def #{update_method} # def _update_full_name
26
26
  self[:#{attribute}] = #{original_method} # self[:full_name] = _unpersistized_full_name
data/persistize.gemspec CHANGED
@@ -1,52 +1,20 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{persistize}
8
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
9
6
 
10
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
8
  s.authors = ["Sergio Gil", "Luismi Cavall\303\251"]
12
- s.date = %q{2010-03-23}
9
+ s.date = %q{2010-04-30}
13
10
  s.email = %q{ballsbreaking@bebanjo.com}
14
- s.extra_rdoc_files = [
15
- "README.rdoc"
16
- ]
17
- s.files = [
18
- ".gitignore",
19
- "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "init.rb",
24
- "lib/persistize.rb",
25
- "persistize.gemspec",
26
- "test/models/company.rb",
27
- "test/models/person.rb",
28
- "test/models/project.rb",
29
- "test/models/task.rb",
30
- "test/models/thing.rb",
31
- "test/models/wadus/thing.rb",
32
- "test/persistize_test.rb",
33
- "test/test_helper.rb"
34
- ]
35
- s.homepage = %q{http://github.com/bebanjo/persistize}
36
- s.rdoc_options = ["--charset=UTF-8"]
11
+ s.extra_rdoc_files = ["README.rdoc"]
12
+ s.files = ["init.rb", "MIT-LICENSE", "persistize.gemspec", "Rakefile", "README.rdoc", "VERSION", "test", "lib/persistize.rb"]
13
+ s.homepage = %q{http://githum.com/bebanjo/persistize}
14
+ s.rdoc_options = ["--main", "README.rdoc"]
37
15
  s.require_paths = ["lib"]
38
- s.rubygems_version = %q{1.3.5}
16
+ s.rubygems_version = %q{1.3.6}
39
17
  s.summary = %q{Easy denormalization for your ActiveRecord models}
40
- s.test_files = [
41
- "test/models/company.rb",
42
- "test/models/person.rb",
43
- "test/models/project.rb",
44
- "test/models/task.rb",
45
- "test/models/thing.rb",
46
- "test/models/wadus/thing.rb",
47
- "test/persistize_test.rb",
48
- "test/test_helper.rb"
49
- ]
50
18
 
51
19
  if s.respond_to? :specification_version then
52
20
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persistize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Sergio Gil
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-03-23 00:00:00 +01:00
18
+ date: 2010-04-30 00:00:00 +02:00
14
19
  default_executable:
15
20
  dependencies: []
16
21
 
@@ -23,56 +28,43 @@ extensions: []
23
28
  extra_rdoc_files:
24
29
  - README.rdoc
25
30
  files:
26
- - .gitignore
31
+ - init.rb
27
32
  - MIT-LICENSE
28
- - README.rdoc
33
+ - persistize.gemspec
29
34
  - Rakefile
35
+ - README.rdoc
30
36
  - VERSION
31
- - init.rb
32
37
  - 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/models/thing.rb
39
- - test/models/wadus/thing.rb
40
- - test/persistize_test.rb
41
- - test/test_helper.rb
42
38
  has_rdoc: true
43
- homepage: http://github.com/bebanjo/persistize
39
+ homepage: http://githum.com/bebanjo/persistize
44
40
  licenses: []
45
41
 
46
42
  post_install_message:
47
43
  rdoc_options:
48
- - --charset=UTF-8
44
+ - --main
45
+ - README.rdoc
49
46
  require_paths:
50
47
  - lib
51
48
  required_ruby_version: !ruby/object:Gem::Requirement
52
49
  requirements:
53
50
  - - ">="
54
51
  - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
55
54
  version: "0"
56
- version:
57
55
  required_rubygems_version: !ruby/object:Gem::Requirement
58
56
  requirements:
59
57
  - - ">="
60
58
  - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
61
  version: "0"
62
- version:
63
62
  requirements: []
64
63
 
65
64
  rubyforge_project:
66
- rubygems_version: 1.3.5
65
+ rubygems_version: 1.3.6
67
66
  signing_key:
68
67
  specification_version: 3
69
68
  summary: Easy denormalization for your ActiveRecord models
70
- test_files:
71
- - test/models/company.rb
72
- - test/models/person.rb
73
- - test/models/project.rb
74
- - test/models/task.rb
75
- - test/models/thing.rb
76
- - test/models/wadus/thing.rb
77
- - test/persistize_test.rb
78
- - test/test_helper.rb
69
+ test_files: []
70
+
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- doc/
2
- persistize-*.gem
@@ -1,10 +0,0 @@
1
- class Company < ActiveRecord::Base
2
- has_many :people
3
- has_many :tasks
4
-
5
- def summary
6
- "#{name} has #{people.count} people and #{tasks.count} tasks"
7
- end
8
-
9
- persistize :summary, :depending_on => [ :people, :tasks ]
10
- end
@@ -1,20 +0,0 @@
1
- class Person < ActiveRecord::Base
2
-
3
- has_many :projects
4
- has_many :tasks, :through => :projects
5
-
6
- def full_name
7
- "#{first_name} #{last_name}"
8
- end
9
-
10
- def initials
11
- "#{first_name.first}#{last_name.first}".upcase
12
- end
13
-
14
- def info
15
- "#{full_name} has #{tasks.count} tasks in #{projects.count} projects"
16
- end
17
-
18
- persistize :full_name, :initials
19
- persistize :info, :depending_on => [:projects, :tasks]
20
- end
@@ -1,10 +0,0 @@
1
- class Project < ActiveRecord::Base
2
- has_many :tasks
3
- belongs_to :person
4
-
5
- def completed?
6
- tasks.any? && tasks.all?(&:completed?)
7
- end
8
-
9
- persistize :completed?, :depending_on => :tasks
10
- end
data/test/models/task.rb DELETED
@@ -1,9 +0,0 @@
1
- class Task < ActiveRecord::Base
2
- belongs_to :project
3
-
4
- def project_name
5
- project && project.name
6
- end
7
-
8
- persistize :project_name, :depending_on => :project
9
- end
data/test/models/thing.rb DELETED
@@ -1,3 +0,0 @@
1
- class Thing < ActiveRecord::Base
2
-
3
- end
@@ -1,8 +0,0 @@
1
- class Wadus::Thing < ActiveRecord::Base
2
- set_table_name :wadus_things
3
- has_many :things, :class_name => "::Thing", :foreign_key => "wadus_thing_id"
4
- def summary
5
- things.map(&:name).join(", ")
6
- end
7
- persistize :summary, :depending_on => :things
8
- end
@@ -1,124 +0,0 @@
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 "call the method when object is dirty" do
33
- @person.first_name = 'Axl'
34
- assert_equal('Axl Hendrix', @person.full_name)
35
- end
36
-
37
- should "call the method when reading before being created" do
38
- person = Person.new(:first_name => "Jimi", :last_name => "Hendrix")
39
- assert_equal('Jimi Hendrix', person.full_name)
40
- end
41
-
42
- should "also persistize #initials" do
43
- assert_equal('JH', @person[:initials])
44
- end
45
-
46
- end
47
-
48
- context "a project with tasks" do
49
-
50
- setup do
51
- @project = Project.create(:name => "Rails")
52
- @task = @project.tasks.create(:completed => true)
53
- end
54
-
55
- should "update @project#completed? when a new task is created" do
56
- Task.create(:project_id => @project.id, :completed => false)
57
- assert !@project.reload[:completed]
58
- end
59
-
60
- should "update @project#completed? when a task is deleted" do
61
- @task.destroy
62
- assert !@project.reload[:completed]
63
- end
64
-
65
- should "update @project#completed? when a task is updated" do
66
- @task.update_attributes!(:completed => false)
67
- assert !@project.reload[:completed]
68
- end
69
-
70
- should "update each task's #project_name when the project name is updated" do
71
- @project.update_attributes!(:name => "Merb")
72
- assert_equal "Merb", @task.reload[:project_name]
73
- end
74
- end
75
-
76
- context "a company with people and tasks" do
77
-
78
- setup do
79
- @company = Company.create(:name => "BeBanjo")
80
- end
81
-
82
- should "update summary when it is created" do
83
- assert_equal("BeBanjo has 0 people and 0 tasks", @company.reload[:summary])
84
- end
85
-
86
- should "update summary when a person is created" do
87
- @company.people.create(:first_name => 'Bruce', :last_name => 'Dickinson')
88
- assert_equal("BeBanjo has 1 people and 0 tasks", @company.reload[:summary])
89
- end
90
-
91
- should "update summary when a task created" do
92
- @company.tasks.create
93
- assert_equal("BeBanjo has 0 people and 1 tasks", @company.reload[:summary])
94
- end
95
-
96
- end
97
-
98
- context "a person with projects and tasks" do
99
-
100
- setup do
101
- @person = Person.create(:first_name => "Enjuto", :last_name => "Mojamuto")
102
- @project = Project.create(:name => "La Hora Chanante", :person => @person)
103
- Project.create(:name => "Wadus", :person => @person)
104
- 3.times { Task.create(:project => @project)}
105
- end
106
-
107
- should "have info" do
108
- assert_equal("Enjuto Mojamuto has 3 tasks in 2 projects", @person.reload[:info])
109
- end
110
- end
111
-
112
- context "namespaced models" do
113
-
114
- should "access to namespaced models" do
115
- @thing = Wadus::Thing.create
116
- 2.times { |i| @thing.things.create(:name => "Thing number #{i + 1}") }
117
- assert_equal("Thing number 1, Thing number 2", @thing.reload[:summary])
118
- end
119
-
120
- end
121
-
122
- end
123
-
124
- end
data/test/test_helper.rb DELETED
@@ -1,49 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
- require 'shoulda'
4
- require 'active_record'
5
- require 'active_support'
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", :database => ":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, :info
19
- t.integer :company_id
20
- end
21
- create_table :projects do |t|
22
- t.string :name
23
- t.boolean :completed
24
- t.integer :person_id
25
- end
26
- create_table :tasks do |t|
27
- t.integer :project_id, :company_id
28
- t.boolean :completed
29
- t.string :project_name
30
- end
31
- create_table :companies do |t|
32
- t.string :name, :summary
33
- end
34
- create_table :wadus_things do |t|
35
- t.string :summary
36
- end
37
- create_table :things do |t|
38
- t.integer :wadus_thing_id
39
- t.string :name
40
- end
41
- end
42
- end
43
-
44
- def drop_db
45
- ActiveRecord::Base.connection.tables.each do |table|
46
- ActiveRecord::Base.connection.drop_table(table)
47
- end
48
- end
49
-