has_defaults 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/MIT-LICENSE +20 -0
- data/README +74 -0
- data/Rakefile +17 -0
- data/has_defaults.gemspec +19 -0
- data/lib/has_defaults/active_record_ext.rb +54 -0
- data/lib/has_defaults/version.rb +5 -0
- data/lib/has_defaults.rb +4 -0
- data/pkg/has_defaults-0.3.0.gem +0 -0
- data/spec/app_root/log/in_memory.log +147 -0
- data/spec/rails2/Gemfile +8 -0
- data/spec/rails2/Gemfile.lock +51 -0
- data/spec/rails2/Rakefile +11 -0
- data/spec/rails2/app_root/app/controllers/application_controller.rb +2 -0
- data/spec/rails2/app_root/app/models/donut.rb +21 -0
- data/spec/rails2/app_root/app/models/model_without_defaults.rb +2 -0
- data/spec/rails2/app_root/app/models/pastry.rb +6 -0
- data/spec/rails2/app_root/config/boot.rb +114 -0
- data/spec/rails2/app_root/config/database.yml +21 -0
- data/spec/rails2/app_root/config/environment.rb +14 -0
- data/spec/rails2/app_root/config/environments/in_memory.rb +0 -0
- data/spec/rails2/app_root/config/environments/mysql.rb +0 -0
- data/spec/rails2/app_root/config/environments/postgresql.rb +0 -0
- data/spec/rails2/app_root/config/environments/sqlite.rb +0 -0
- data/spec/rails2/app_root/config/environments/sqlite3.rb +0 -0
- data/spec/rails2/app_root/config/routes.rb +4 -0
- data/spec/rails2/app_root/db/migrate/001_create_pastries.rb +18 -0
- data/spec/rails2/app_root/db/migrate/002_create_model_without_defaults.rb +12 -0
- data/spec/rails2/app_root/lib/console_with_fixtures.rb +4 -0
- data/spec/rails2/app_root/log/.gitignore +1 -0
- data/spec/rails2/app_root/script/console +7 -0
- data/spec/rails2/has_defaults_spec.rb +79 -0
- data/spec/rails2/rcov.opts +2 -0
- data/spec/rails2/spec.opts +4 -0
- data/spec/rails2/spec_helper.rb +20 -0
- data/spec/rails3/.rspec +2 -0
- data/spec/rails3/Gemfile +9 -0
- data/spec/rails3/Gemfile.lock +101 -0
- data/spec/rails3/Rakefile +10 -0
- data/spec/rails3/app_root/.gitignore +4 -0
- data/spec/rails3/app_root/app/controllers/application_controller.rb +2 -0
- data/spec/rails3/app_root/app/models/donut.rb +21 -0
- data/spec/rails3/app_root/app/models/model_without_defaults.rb +2 -0
- data/spec/rails3/app_root/app/models/pastry.rb +6 -0
- data/spec/rails3/app_root/config/application.rb +32 -0
- data/spec/rails3/app_root/config/boot.rb +13 -0
- data/spec/rails3/app_root/config/database.yml +21 -0
- data/spec/rails3/app_root/config/environment.rb +5 -0
- data/spec/rails3/app_root/config/environments/in_memory.rb +0 -0
- data/spec/rails3/app_root/config/environments/mysql.rb +0 -0
- data/spec/rails3/app_root/config/environments/postgresql.rb +0 -0
- data/spec/rails3/app_root/config/environments/sqlite.rb +0 -0
- data/spec/rails3/app_root/config/environments/sqlite3.rb +0 -0
- data/spec/rails3/app_root/config/environments/test.rb +35 -0
- data/spec/rails3/app_root/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3/app_root/config/initializers/inflections.rb +10 -0
- data/spec/rails3/app_root/config/initializers/mime_types.rb +5 -0
- data/spec/rails3/app_root/config/initializers/secret_token.rb +7 -0
- data/spec/rails3/app_root/config/initializers/session_store.rb +8 -0
- data/spec/rails3/app_root/config/locales/en.yml +5 -0
- data/spec/rails3/app_root/config/routes.rb +58 -0
- data/spec/rails3/app_root/db/migrate/001_create_pastries.rb +18 -0
- data/spec/rails3/app_root/db/migrate/002_create_model_without_defaults.rb +12 -0
- data/spec/rails3/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails3/app_root/log/.gitkeep +0 -0
- data/spec/rails3/app_root/script/rails +6 -0
- data/spec/rails3/has_defaults_spec.rb +74 -0
- data/spec/rails3/log/in_memory.log +33 -0
- data/spec/rails3/rcov.opts +2 -0
- data/spec/rails3/spec_helper.rb +21 -0
- metadata +149 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Nando Vieira
|
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/README
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
has_defaults
|
2
|
+
============
|
3
|
+
|
4
|
+
Default values for ActiveRecord models.
|
5
|
+
|
6
|
+
INSTALLATION
|
7
|
+
------------
|
8
|
+
|
9
|
+
In your `Gemfile`
|
10
|
+
|
11
|
+
gem 'has_defaults'
|
12
|
+
|
13
|
+
Now run
|
14
|
+
|
15
|
+
bundle install
|
16
|
+
|
17
|
+
|
18
|
+
USAGE
|
19
|
+
-----
|
20
|
+
|
21
|
+
Add the method call `has_defaults` to your model.
|
22
|
+
|
23
|
+
class Page < ActiveRecord::Base
|
24
|
+
has_defaults :title => "New page", :body => "Put your text here"
|
25
|
+
end
|
26
|
+
|
27
|
+
Attributes will be set only if it's a new record and the attribute is blank.
|
28
|
+
|
29
|
+
Retrieve the default attribute with the `default_for` instance method:
|
30
|
+
|
31
|
+
@page.default_for(:title)
|
32
|
+
|
33
|
+
You can pass Proc as attribute:
|
34
|
+
|
35
|
+
has_defaults :expires_at => proc { Time.now }
|
36
|
+
|
37
|
+
You can override the default attributes as follow:
|
38
|
+
|
39
|
+
Page.has_defaults_options = {:title => "Here's your new page", :body => "Write your page text"}
|
40
|
+
|
41
|
+
NOTE
|
42
|
+
----
|
43
|
+
|
44
|
+
Is **Ruby 1.9** ready!
|
45
|
+
|
46
|
+
MAINTAINER
|
47
|
+
----------
|
48
|
+
|
49
|
+
* Original version by Nando Vieira (<http://simplesideias.com.br>)
|
50
|
+
* Patches in this fork by Henning Koch (<http://www.makandra.de/>)
|
51
|
+
|
52
|
+
LICENSE:
|
53
|
+
--------
|
54
|
+
|
55
|
+
(The MIT License)
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
58
|
+
a copy of this software and associated documentation files (the
|
59
|
+
'Software'), to deal in the Software without restriction, including
|
60
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
61
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
62
|
+
permit persons to whom the Software is furnished to do so, subject to
|
63
|
+
the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
70
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
71
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
72
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
73
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
74
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
|
5
|
+
desc 'Default: Run all specs.'
|
6
|
+
task :default => :all_specs
|
7
|
+
|
8
|
+
desc "Run all specs"
|
9
|
+
task :all_specs do
|
10
|
+
Dir['spec/**/Rakefile'].each do |rakefile|
|
11
|
+
directory_name = File.dirname(rakefile)
|
12
|
+
sh <<-CMD
|
13
|
+
cd #{directory_name}
|
14
|
+
bundle exec rake
|
15
|
+
CMD
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "has_defaults/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'has_defaults'
|
6
|
+
s.version = HasDefaults::VERSION
|
7
|
+
s.authors = ["Henning Koch"]
|
8
|
+
s.email = 'henning.koch@makandra.de'
|
9
|
+
s.homepage = 'https://github.com/makandra/has_defaults'
|
10
|
+
s.summary = 'Default values for ActiveRecord models.'
|
11
|
+
s.description = s.summary
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_dependency('rspec')
|
19
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module HasDefaults
|
2
|
+
module ActiveRecordExt
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def has_defaults(attrs)
|
7
|
+
raise "Hash expected; #{attrs.class} given." unless attrs.is_a?(Hash)
|
8
|
+
|
9
|
+
include InstanceMethods
|
10
|
+
|
11
|
+
unless respond_to?(:has_defaults_options)
|
12
|
+
class_inheritable_hash :has_defaults_options
|
13
|
+
end
|
14
|
+
|
15
|
+
self.has_defaults_options ||= {}
|
16
|
+
self.has_defaults_options.merge!(attrs)
|
17
|
+
|
18
|
+
if Rails.version < '3'
|
19
|
+
# ActiveRecord only calls after_initialize callbacks only if is
|
20
|
+
# explicit defined in a class. We should however only define that
|
21
|
+
# callback if a default has been set, as it really slow downs Rails.
|
22
|
+
unless method_defined?(:after_initialize)
|
23
|
+
define_method(:after_initialize) {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
after_initialize :set_default_attributes
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
module InstanceMethods
|
33
|
+
|
34
|
+
def default_for(name)
|
35
|
+
self.class.has_defaults_options[name.to_sym]
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def set_default_attributes
|
41
|
+
if new_record?
|
42
|
+
self.class.has_defaults_options.each do |name, value|
|
43
|
+
if send(name).nil?
|
44
|
+
value = instance_eval(&value) if value.respond_to?(:call)
|
45
|
+
send("#{name}=", value)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/has_defaults.rb
ADDED
Binary file
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# Logfile created on Mon Mar 22 10:14:11 +0100 2010 [4;36;1mSQL (0.5ms)[0m [0;1m SELECT name
|
2
|
+
FROM sqlite_master
|
3
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
4
|
+
[0m
|
5
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
6
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
7
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
8
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
9
|
+
FROM sqlite_master
|
10
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
11
|
+
[0m
|
12
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
13
|
+
Migrating to CreatePastries (1)
|
14
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
15
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
16
|
+
Migrating to CreateModelWithoutDefaults (2)
|
17
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
18
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
19
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
20
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
21
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
22
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
23
|
+
FROM sqlite_master
|
24
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
25
|
+
[0m
|
26
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
27
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
28
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
29
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
30
|
+
FROM sqlite_master
|
31
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
32
|
+
[0m
|
33
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
34
|
+
Migrating to CreatePastries (1)
|
35
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
36
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
37
|
+
Migrating to CreateModelWithoutDefaults (2)
|
38
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
39
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
40
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
41
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
42
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
43
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
44
|
+
FROM sqlite_master
|
45
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
46
|
+
[0m
|
47
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
48
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
49
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
50
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
51
|
+
FROM sqlite_master
|
52
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
53
|
+
[0m
|
54
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
55
|
+
Migrating to CreatePastries (1)
|
56
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
57
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
58
|
+
Migrating to CreateModelWithoutDefaults (2)
|
59
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
60
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
61
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
62
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
63
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
64
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
65
|
+
FROM sqlite_master
|
66
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
67
|
+
[0m
|
68
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
69
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
70
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
71
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
72
|
+
FROM sqlite_master
|
73
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
74
|
+
[0m
|
75
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
76
|
+
Migrating to CreatePastries (1)
|
77
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
78
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
79
|
+
Migrating to CreateModelWithoutDefaults (2)
|
80
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
81
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
82
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
83
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
84
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
85
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
86
|
+
FROM sqlite_master
|
87
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
88
|
+
[0m
|
89
|
+
[4;35;1mSQL (0.7ms)[0m [0mselect sqlite_version(*)[0m
|
90
|
+
[4;36;1mSQL (0.8ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
91
|
+
[4;35;1mSQL (0.5ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
92
|
+
[4;36;1mSQL (0.6ms)[0m [0;1m SELECT name
|
93
|
+
FROM sqlite_master
|
94
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
95
|
+
[0m
|
96
|
+
[4;35;1mSQL (0.3ms)[0m [0mSELECT version FROM schema_migrations[0m
|
97
|
+
Migrating to CreatePastries (1)
|
98
|
+
[4;36;1mSQL (0.9ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
99
|
+
[4;35;1mSQL (0.3ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
100
|
+
Migrating to CreateModelWithoutDefaults (2)
|
101
|
+
[4;36;1mSQL (0.6ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
102
|
+
[4;35;1mSQL (0.3ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
103
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
104
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
105
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
106
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
107
|
+
FROM sqlite_master
|
108
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
109
|
+
[0m
|
110
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
111
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
112
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
113
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
114
|
+
FROM sqlite_master
|
115
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
116
|
+
[0m
|
117
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
118
|
+
Migrating to CreatePastries (1)
|
119
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
120
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
121
|
+
Migrating to CreateModelWithoutDefaults (2)
|
122
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
123
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
124
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
125
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
126
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
127
|
+
[4;36;1mSQL (0.3ms)[0m [0;1m SELECT name
|
128
|
+
FROM sqlite_master
|
129
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
130
|
+
[0m
|
131
|
+
[4;35;1mSQL (0.2ms)[0m [0mselect sqlite_version(*)[0m
|
132
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
133
|
+
[4;35;1mSQL (0.2ms)[0m [0mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
134
|
+
[4;36;1mSQL (0.2ms)[0m [0;1m SELECT name
|
135
|
+
FROM sqlite_master
|
136
|
+
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
|
137
|
+
[0m
|
138
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM schema_migrations[0m
|
139
|
+
Migrating to CreatePastries (1)
|
140
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCREATE TABLE "pastries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "type" varchar(255), "flavor" varchar(255), "name" varchar(255), "maker" varchar(255), "main_ingredient" varchar(255)) [0m
|
141
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('1')[0m
|
142
|
+
Migrating to CreateModelWithoutDefaults (2)
|
143
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mCREATE TABLE "model_without_defaults" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL) [0m
|
144
|
+
[4;35;1mSQL (0.1ms)[0m [0mINSERT INTO schema_migrations (version) VALUES ('2')[0m
|
145
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'vanilla')[0m
|
146
|
+
[4;35;1mDonut Load (0.3ms)[0m [0mSELECT * FROM "pastries" WHERE ( ("pastries"."type" = 'Donut' ) ) LIMIT 1[0m
|
147
|
+
[4;36;1mDonut Create (0.1ms)[0m [0;1mINSERT INTO "pastries" ("name", "main_ingredient", "type", "maker", "flavor") VALUES('Cream', 'flour', 'Donut', 'Dunkin Donuts', 'cream')[0m
|
data/spec/rails2/Gemfile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../..
|
3
|
+
specs:
|
4
|
+
has_defaults (0.3.0)
|
5
|
+
rspec
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (2.3.10)
|
11
|
+
actionpack (= 2.3.10)
|
12
|
+
actionpack (2.3.10)
|
13
|
+
activesupport (= 2.3.10)
|
14
|
+
rack (~> 1.1.0)
|
15
|
+
activerecord (2.3.10)
|
16
|
+
activesupport (= 2.3.10)
|
17
|
+
activeresource (2.3.10)
|
18
|
+
activesupport (= 2.3.10)
|
19
|
+
activesupport (2.3.10)
|
20
|
+
columnize (0.3.2)
|
21
|
+
linecache (0.43)
|
22
|
+
rack (1.1.0)
|
23
|
+
rails (2.3.10)
|
24
|
+
actionmailer (= 2.3.10)
|
25
|
+
actionpack (= 2.3.10)
|
26
|
+
activerecord (= 2.3.10)
|
27
|
+
activeresource (= 2.3.10)
|
28
|
+
activesupport (= 2.3.10)
|
29
|
+
rake (>= 0.8.3)
|
30
|
+
rake (0.8.7)
|
31
|
+
rspec (1.3.1)
|
32
|
+
rspec-rails (1.3.3)
|
33
|
+
rack (>= 1.0.0)
|
34
|
+
rspec (= 1.3.1)
|
35
|
+
ruby-debug (0.10.4)
|
36
|
+
columnize (>= 0.1)
|
37
|
+
ruby-debug-base (~> 0.10.4.0)
|
38
|
+
ruby-debug-base (0.10.4)
|
39
|
+
linecache (>= 0.3)
|
40
|
+
sqlite3 (1.3.6)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
has_defaults!
|
47
|
+
rails (= 2.3.10)
|
48
|
+
rspec (< 2)
|
49
|
+
rspec-rails (< 2)
|
50
|
+
ruby-debug
|
51
|
+
sqlite3
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc 'Default: Run all specs for a specific rails version.'
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc "Run all specs for a specific rails version"
|
8
|
+
Spec::Rake::SpecTask.new() do |t|
|
9
|
+
t.spec_opts = ['--options', "\"spec.opts\""]
|
10
|
+
t.spec_files = FileList['**/*_spec.rb']
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Donut < Pastry
|
2
|
+
|
3
|
+
has_defaults :flavor => "cream", :name => "Cream"
|
4
|
+
has_defaults :maker => proc { "Dunkin Donuts" }
|
5
|
+
has_defaults :weight => proc { weigh }
|
6
|
+
|
7
|
+
def flavor
|
8
|
+
@flavor_getter_called = true
|
9
|
+
read_attribute(:flavor)
|
10
|
+
end
|
11
|
+
|
12
|
+
def flavor=(value)
|
13
|
+
@flavor_setter_called = true
|
14
|
+
write_attribute(:flavor, value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def weigh
|
18
|
+
"a lot"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# Allow customization of the rails framework path
|
2
|
+
RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
|
3
|
+
|
4
|
+
# Don't change this file!
|
5
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
6
|
+
|
7
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
class << self
|
11
|
+
def boot!
|
12
|
+
unless booted?
|
13
|
+
preinitialize
|
14
|
+
pick_boot.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def booted?
|
19
|
+
defined? Rails::Initializer
|
20
|
+
end
|
21
|
+
|
22
|
+
def pick_boot
|
23
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendor_rails?
|
27
|
+
File.exist?(RAILS_FRAMEWORK_ROOT)
|
28
|
+
end
|
29
|
+
|
30
|
+
def preinitialize
|
31
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def preinitializer_path
|
35
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Boot
|
40
|
+
def run
|
41
|
+
load_initializer
|
42
|
+
Rails::Initializer.run(:set_load_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class VendorBoot < Boot
|
47
|
+
def load_initializer
|
48
|
+
require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
|
49
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class GemBoot < Boot
|
54
|
+
def load_initializer
|
55
|
+
self.class.load_rubygems
|
56
|
+
load_rails_gem
|
57
|
+
require 'initializer'
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_rails_gem
|
61
|
+
if version = self.class.gem_version
|
62
|
+
gem 'rails', version
|
63
|
+
else
|
64
|
+
gem 'rails'
|
65
|
+
end
|
66
|
+
rescue Gem::LoadError => load_error
|
67
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
|
71
|
+
class << self
|
72
|
+
def rubygems_version
|
73
|
+
Gem::RubyGemsVersion rescue nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def gem_version
|
77
|
+
if defined? RAILS_GEM_VERSION
|
78
|
+
RAILS_GEM_VERSION
|
79
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
80
|
+
ENV['RAILS_GEM_VERSION']
|
81
|
+
else
|
82
|
+
parse_gem_version(read_environment_rb)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_rubygems
|
87
|
+
require 'rubygems'
|
88
|
+
min_version = '1.1.1'
|
89
|
+
unless rubygems_version >= min_version
|
90
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
91
|
+
exit 1
|
92
|
+
end
|
93
|
+
|
94
|
+
rescue LoadError
|
95
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
96
|
+
exit 1
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse_gem_version(text)
|
100
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
def read_environment_rb
|
105
|
+
environment_rb = "#{RAILS_ROOT}/config/environment.rb"
|
106
|
+
environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
|
107
|
+
File.read(environment_rb)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# All that for this:
|
114
|
+
Rails.boot!
|
@@ -0,0 +1,21 @@
|
|
1
|
+
in_memory:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: ":memory:"
|
4
|
+
verbosity: quiet
|
5
|
+
sqlite:
|
6
|
+
adapter: sqlite
|
7
|
+
dbfile: plugin_test.sqlite.db
|
8
|
+
sqlite3:
|
9
|
+
adapter: sqlite3
|
10
|
+
dbfile: plugin_test.sqlite3.db
|
11
|
+
postgresql:
|
12
|
+
adapter: postgresql
|
13
|
+
username: postgres
|
14
|
+
password: postgres
|
15
|
+
database: plugin_test
|
16
|
+
mysql:
|
17
|
+
adapter: mysql
|
18
|
+
host: localhost
|
19
|
+
username: root
|
20
|
+
password:
|
21
|
+
database: plugin_test
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
2
|
+
|
3
|
+
Rails::Initializer.run do |config|
|
4
|
+
config.cache_classes = false
|
5
|
+
config.whiny_nils = true
|
6
|
+
config.action_controller.session = { :key => "_myapp_session", :secret => "gwirofjweroijger8924rt2zfwehfuiwehb1378rifowenfoqwphf23" }
|
7
|
+
config.plugin_locators.unshift(
|
8
|
+
Class.new(Rails::Plugin::Locator) do
|
9
|
+
def plugins
|
10
|
+
[Rails::Plugin.new(File.expand_path('.'))]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
) unless defined?(PluginTestHelper::PluginLocator)
|
14
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreatePastries < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :pastries do |t|
|
5
|
+
t.string :type
|
6
|
+
t.string :flavor
|
7
|
+
t.string :name
|
8
|
+
t.string :maker
|
9
|
+
t.string :weight
|
10
|
+
t.string :main_ingredient
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :pastries
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|