railsex 1.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.
Files changed (57) hide show
  1. data/CHANGELOG +5 -0
  2. data/LICENSE +3 -0
  3. data/Manifest +55 -0
  4. data/README +53 -0
  5. data/init.rb +27 -0
  6. data/lib/actionpack/mime_responds_extension.rb +46 -0
  7. data/lib/activerecord/changed.rb +52 -0
  8. data/lib/railties/console.rb +10 -0
  9. data/railsex.gemspec +30 -0
  10. data/test/Rakefile +8 -0
  11. data/test/app/controllers/application.rb +4 -0
  12. data/test/app/controllers/people_controller.rb +73 -0
  13. data/test/app/helpers/application_helper.rb +3 -0
  14. data/test/app/helpers/people_helper.rb +2 -0
  15. data/test/app/models/person.rb +4 -0
  16. data/test/app/views/layouts/application.html.erb +16 -0
  17. data/test/app/views/people/edit.html.erb +27 -0
  18. data/test/app/views/people/index.html.erb +24 -0
  19. data/test/app/views/people/new.html.erb +26 -0
  20. data/test/app/views/people/show.html.erb +18 -0
  21. data/test/config/boot.rb +109 -0
  22. data/test/config/database.yml +19 -0
  23. data/test/config/environment.rb +13 -0
  24. data/test/config/environments/development.rb +18 -0
  25. data/test/config/environments/production.rb +19 -0
  26. data/test/config/environments/test.rb +22 -0
  27. data/test/config/routes.rb +4 -0
  28. data/test/db/development.sqlite3 +0 -0
  29. data/test/db/migrate/001_create_people.rb +15 -0
  30. data/test/db/migrate/002_add_stuff_to_person.rb +11 -0
  31. data/test/db/schema.rb +24 -0
  32. data/test/db/test.sqlite3 +0 -0
  33. data/test/public/404.html +30 -0
  34. data/test/public/422.html +30 -0
  35. data/test/public/500.html +30 -0
  36. data/test/public/dispatch.cgi +10 -0
  37. data/test/public/dispatch.fcgi +24 -0
  38. data/test/public/dispatch.rb +10 -0
  39. data/test/public/favicon.ico +0 -0
  40. data/test/script/about +3 -0
  41. data/test/script/console +3 -0
  42. data/test/script/destroy +3 -0
  43. data/test/script/generate +3 -0
  44. data/test/script/performance/benchmarker +3 -0
  45. data/test/script/performance/profiler +3 -0
  46. data/test/script/performance/request +3 -0
  47. data/test/script/plugin +3 -0
  48. data/test/script/process/inspector +3 -0
  49. data/test/script/process/reaper +3 -0
  50. data/test/script/process/spawner +3 -0
  51. data/test/script/runner +3 -0
  52. data/test/script/server +3 -0
  53. data/test/test/fixtures/people.yml +11 -0
  54. data/test/test/functional/people_controller_test.rb +45 -0
  55. data/test/test/test_helper.rb +10 -0
  56. data/test/test/unit/person_test.rb +64 -0
  57. metadata +108 -0
@@ -0,0 +1,5 @@
1
+ v1.2. Load extensions only on demand.
2
+
3
+ v1.1. Added support for declarative lazy updates
4
+
5
+ v1.0. Added argument-less version of respond_to
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2007 Pratik Naik ( http://m.onkey.org )
2
+
3
+ The Library is dual licensed under terms of Ruby License or MIT License.
@@ -0,0 +1,55 @@
1
+ CHANGELOG
2
+ init.rb
3
+ lib/actionpack/mime_responds_extension.rb
4
+ lib/activerecord/changed.rb
5
+ lib/railties/console.rb
6
+ LICENSE
7
+ Manifest
8
+ README
9
+ test/app/controllers/application.rb
10
+ test/app/controllers/people_controller.rb
11
+ test/app/helpers/application_helper.rb
12
+ test/app/helpers/people_helper.rb
13
+ test/app/models/person.rb
14
+ test/app/views/layouts/application.html.erb
15
+ test/app/views/people/edit.html.erb
16
+ test/app/views/people/index.html.erb
17
+ test/app/views/people/new.html.erb
18
+ test/app/views/people/show.html.erb
19
+ test/config/boot.rb
20
+ test/config/database.yml
21
+ test/config/environment.rb
22
+ test/config/environments/development.rb
23
+ test/config/environments/production.rb
24
+ test/config/environments/test.rb
25
+ test/config/routes.rb
26
+ test/db/development.sqlite3
27
+ test/db/migrate/001_create_people.rb
28
+ test/db/migrate/002_add_stuff_to_person.rb
29
+ test/db/schema.rb
30
+ test/db/test.sqlite3
31
+ test/public/404.html
32
+ test/public/422.html
33
+ test/public/500.html
34
+ test/public/dispatch.cgi
35
+ test/public/dispatch.fcgi
36
+ test/public/dispatch.rb
37
+ test/public/favicon.ico
38
+ test/Rakefile
39
+ test/script/about
40
+ test/script/console
41
+ test/script/destroy
42
+ test/script/generate
43
+ test/script/performance/benchmarker
44
+ test/script/performance/profiler
45
+ test/script/performance/request
46
+ test/script/plugin
47
+ test/script/process/inspector
48
+ test/script/process/reaper
49
+ test/script/process/spawner
50
+ test/script/runner
51
+ test/script/server
52
+ test/test/fixtures/people.yml
53
+ test/test/functional/people_controller_test.rb
54
+ test/test/test_helper.rb
55
+ test/test/unit/person_test.rb
data/README ADDED
@@ -0,0 +1,53 @@
1
+ ~[ Description ]~
2
+
3
+ Railsex - pronounced "Rails Extensions" OR "Ex Rails" ( easier to say ) - is a plugin for all those cool/good to have/experimental features
4
+ which cannot possibly be in core due to their nature. As rails itself, this plugin is supposed to be a community effort. So, do chime in !
5
+
6
+ ~[ How to use ]~
7
+
8
+ Railsex loads extensions only on demand because of the variety of options it provides.
9
+
10
+ You will need to load the extension in your environment.rb configuration block with following syntax :
11
+
12
+ config.after_initialize do
13
+ config.extenstions = [:respond_to, :lazy_attributes, :console]
14
+ end
15
+
16
+ The plugin requires Rails 2.0.x or higher version.
17
+
18
+ ~[ Current Extensions ]~
19
+ - respond_to
20
+ - lazy_attributes
21
+ - console
22
+
23
+ ~[ Current Features ]~
24
+
25
+ * Argument-less support for respond_to :
26
+
27
+ In your controller you can have :
28
+
29
+ respond_to do
30
+ html
31
+ xml { render :xml => @article }
32
+ end
33
+
34
+ * Lazy attributes to provide partial updates
35
+
36
+ You can declare lazy attributes in your model definition :
37
+
38
+ class Person < ActiveRecord::Base
39
+ lazy_attributes :history, :bio
40
+ end
41
+
42
+ In this case, when you do @person.save, ActiveRecord will include bio and history columns in UPDATE query only if you accessed
43
+ @person.history= or @person.bio= methods.
44
+
45
+ * Very common console tricks
46
+ - [] finders for model so you can do Article[1], Article[:all]
47
+ - "log_to" function to print out db queries to rails irb console
48
+
49
+ ~[ Primary Authors ]~
50
+
51
+ Pratik Naik - http://m.onkey.org
52
+ Unknown people from the internet for "console" extension
53
+
data/init.rb ADDED
@@ -0,0 +1,27 @@
1
+ RAILSEX_MAPPING = { 'console' => 'railties/console',
2
+ 'lazy_attributes' => 'activerecord/changed',
3
+ 'respond_to' => 'actionpack/mime_responds_extension' }
4
+
5
+ class Rails::Configuration
6
+ attr_accessor :extenstions
7
+
8
+ def extenstions
9
+ Array(@extenstions).map(&:to_s)
10
+ end
11
+ end
12
+
13
+ class Rails::Initializer
14
+ def load_application_initializers_with_railsex
15
+ load_application_initializers_without_railsex
16
+
17
+ unless configuration.extenstions.to_set.subset?(RAILSEX_MAPPING.keys.to_set)
18
+ raise "Invalid Extension Supplied. Valid extensions are : #{RAILSEX_MAPPING.keys.join(', ')}"
19
+ end
20
+
21
+ configuration.extenstions.each do |extn|
22
+ RAILS_DEFAULT_LOGGER.info "[Railsex] Loading #{extn}"
23
+ require RAILSEX_MAPPING[extn]
24
+ end
25
+ end
26
+ alias_method_chain :load_application_initializers, :railsex
27
+ end
@@ -0,0 +1,46 @@
1
+ module ActionController
2
+
3
+ module MimeRespondsExtension
4
+ def respond_to(*types, &block)
5
+ raise ArgumentError, "respond_to takes either types or a block, never both" unless types.any? ^ block
6
+ block ||= lambda { |responder| types.each { |type| responder.send(type) } }
7
+ arity = (block.arity == 1)
8
+ responder = ActionController::MimeResponds::Responder.new(self, arity)
9
+ arity ? block.call(responder) : responder.instance_eval(&block)
10
+ responder.respond
11
+ end
12
+ end
13
+
14
+ module ResponderExtension
15
+ def self.included(base)
16
+ base.alias_method_chain :initialize, :arity
17
+ base.alias_method_chain :custom, :arity
18
+ end
19
+
20
+ def initialize_with_arity(controller, arity)
21
+ @arity = arity
22
+ initialize_without_arity(controller)
23
+ end
24
+
25
+ def custom_with_arity(mime_type, &block)
26
+ mime_type = mime_type.is_a?(Mime::Type) ? mime_type : Mime::Type.lookup(mime_type.to_s)
27
+
28
+ @order << mime_type
29
+
30
+ @responses[mime_type] = Proc.new do
31
+ @response.template.template_format = mime_type.to_sym
32
+ @response.content_type = mime_type.to_s
33
+ if block_given?
34
+ @arity ? block.call : @controller.instance_eval(&block)
35
+ else
36
+ @controller.send(:render, :action => @controller.action_name)
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ ActionController::Base.send :include, ActionController::MimeRespondsExtension
46
+ ActionController::MimeResponds::Responder.send :include, ActionController::ResponderExtension
@@ -0,0 +1,52 @@
1
+ module ActiveRecord
2
+ module Changed
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.alias_method_chain :attributes_with_quotes, :changed
6
+ base.alias_method_chain :write_attribute, :changed
7
+ base.alias_method_chain :save, :changed
8
+ base.alias_method_chain :save!, :changed
9
+ base.alias_method_chain :reload, :changed
10
+ end
11
+
12
+ module ClassMethods
13
+ def lazy_attributes(*args)
14
+ @@lazy_attributes ||= Array(args).map(&:to_s).to_set
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def attributes_with_quotes_with_changed(include_primary_key = true, include_readonly_attributes = true)
21
+ original = attributes_with_quotes_without_changed(include_primary_key, include_readonly_attributes)
22
+
23
+ # Reject only if both supplied arguments are false
24
+ original.reject! { |key, value| changed_lazy.include?(key) } if !(include_primary_key || include_readonly_attributes)
25
+ original
26
+ end
27
+
28
+ def write_attribute_with_changed(attr_name, value)
29
+ changed_lazy.delete(attr_name.to_s)
30
+ write_attribute_without_changed(attr_name, value)
31
+ end
32
+
33
+ def reload_with_changed
34
+ @changed_lazy = nil
35
+ reload_without_changed
36
+ end
37
+
38
+ def changed_lazy
39
+ @changed_lazy ||= self.class.lazy_attributes.clone
40
+ end
41
+
42
+ def save_with_changed
43
+ save_without_changed ensure @changed_lazy = nil
44
+ end
45
+
46
+ def save_with_changed!
47
+ save_without_changed! ensure @changed_lazy = nil
48
+ end
49
+ end
50
+ end
51
+
52
+ ActiveRecord::Base.send :include, ActiveRecord::Changed
@@ -0,0 +1,10 @@
1
+ def log_to(stream=$stdout)
2
+ ActiveRecord::Base.logger = Logger.new(stream)
3
+ ActiveRecord::Base.clear_active_connections!
4
+ end
5
+
6
+ class ActiveRecord::Base
7
+ def self.[](*options)
8
+ self.find(*options)
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+
2
+ # Gem::Specification for Railsex-1.2
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{railsex}
7
+ s.version = "1.2"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = [""]
13
+ s.date = %q{2007-12-20}
14
+ s.description = %q{}
15
+ s.email = %q{}
16
+ s.files = ["CHANGELOG", "init.rb", "lib/actionpack/mime_responds_extension.rb", "lib/activerecord/changed.rb", "lib/railties/console.rb", "LICENSE", "Manifest", "README", "test/app/controllers/application.rb", "test/app/controllers/people_controller.rb", "test/app/helpers/application_helper.rb", "test/app/helpers/people_helper.rb", "test/app/models/person.rb", "test/app/views/layouts/application.html.erb", "test/app/views/people/edit.html.erb", "test/app/views/people/index.html.erb", "test/app/views/people/new.html.erb", "test/app/views/people/show.html.erb", "test/config/boot.rb", "test/config/database.yml", "test/config/environment.rb", "test/config/environments/development.rb", "test/config/environments/production.rb", "test/config/environments/test.rb", "test/config/routes.rb", "test/db/development.sqlite3", "test/db/migrate/001_create_people.rb", "test/db/migrate/002_add_stuff_to_person.rb", "test/db/schema.rb", "test/db/test.sqlite3", "test/public/404.html", "test/public/422.html", "test/public/500.html", "test/public/dispatch.cgi", "test/public/dispatch.fcgi", "test/public/dispatch.rb", "test/public/favicon.ico", "test/Rakefile", "test/script/about", "test/script/console", "test/script/destroy", "test/script/generate", "test/script/performance/benchmarker", "test/script/performance/profiler", "test/script/performance/request", "test/script/plugin", "test/script/process/inspector", "test/script/process/reaper", "test/script/process/spawner", "test/script/runner", "test/script/server", "test/test/fixtures/people.yml", "test/test/functional/people_controller_test.rb", "test/test/test_helper.rb", "test/test/unit/person_test.rb", "railsex.gemspec"]
17
+ s.has_rdoc = true
18
+ s.homepage = %q{}
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{railsex}
21
+ s.rubygems_version = %q{0.9.5}
22
+ s.summary = %q{}
23
+ s.test_files = ["test/test/test_helper.rb"]
24
+ end
25
+
26
+
27
+ # # Original Rakefile source (requires the Echoe gem):
28
+ #
29
+ # require 'echoe'
30
+ # Echoe.new('railsex')
@@ -0,0 +1,8 @@
1
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ require 'tasks/rails'
8
+
@@ -0,0 +1,4 @@
1
+ class ApplicationController < ActionController::Base
2
+ helper :all # include all helpers, all the time
3
+ protect_from_forgery
4
+ end
@@ -0,0 +1,73 @@
1
+ class PeopleController < ApplicationController
2
+
3
+ def index
4
+ @people = Person.find(:all)
5
+
6
+ respond_to do
7
+ html
8
+ xml { render :xml => @people }
9
+ end
10
+ end
11
+
12
+ def show
13
+ @person = Person.find(params[:id])
14
+
15
+ respond_to do
16
+ html
17
+ xml { render :xml => @person }
18
+ end
19
+ end
20
+
21
+ def new
22
+ @person = Person.new
23
+
24
+ respond_to do
25
+ html
26
+ xml { render :xml => @person }
27
+ end
28
+ end
29
+
30
+ def edit
31
+ @person = Person.find(params[:id])
32
+ end
33
+
34
+ def create
35
+ @person = Person.new(params[:person])
36
+
37
+ respond_to do |format|
38
+ if @person.save
39
+ flash[:notice] = 'Person was successfully created.'
40
+ format.html { redirect_to(@person) }
41
+ format.xml { render :xml => @person, :status => :created, :location => @person }
42
+ else
43
+ format.html { render :action => "new" }
44
+ format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
45
+ end
46
+ end
47
+ end
48
+
49
+ def update
50
+ @person = Person.find(params[:id])
51
+
52
+ respond_to do |format|
53
+ if @person.update_attributes(params[:person])
54
+ flash[:notice] = 'Person was successfully updated.'
55
+ format.html { redirect_to(@person) }
56
+ format.xml { head :ok }
57
+ else
58
+ format.html { render :action => "edit" }
59
+ format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
60
+ end
61
+ end
62
+ end
63
+
64
+ def destroy
65
+ @person = Person.find(params[:id])
66
+ @person.destroy
67
+
68
+ respond_to do |format|
69
+ format.html { redirect_to(people_url) }
70
+ format.xml { head :ok }
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,2 @@
1
+ module PeopleHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ lazy_attributes :history, :bio
3
+ validates_presence_of :name, :address, :age
4
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title>People: <%= controller.action_name %></title>
8
+ </head>
9
+ <body>
10
+
11
+ <p style="color: green"><%= flash[:notice] %></p>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
@@ -0,0 +1,27 @@
1
+ <h1>Editing person</h1>
2
+
3
+ <%= error_messages_for :person %>
4
+
5
+ <% form_for(@person) do |f| %>
6
+ <p>
7
+ <b>Name</b><br />
8
+ <%= f.text_field :name %>
9
+ </p>
10
+
11
+ <p>
12
+ <b>Address</b><br />
13
+ <%= f.text_area :address %>
14
+ </p>
15
+
16
+ <p>
17
+ <b>Age</b><br />
18
+ <%= f.text_field :age %>
19
+ </p>
20
+
21
+ <p>
22
+ <%= f.submit "Update" %>
23
+ </p>
24
+ <% end %>
25
+
26
+ <%= link_to 'Show', @person %> |
27
+ <%= link_to 'Back', people_path %>
@@ -0,0 +1,24 @@
1
+ <h1>Listing people</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Address</th>
7
+ <th>Age</th>
8
+ </tr>
9
+
10
+ <% for person in @people %>
11
+ <tr>
12
+ <td><%=h person.name %></td>
13
+ <td><%=h person.address %></td>
14
+ <td><%=h person.age %></td>
15
+ <td><%= link_to 'Show', person %></td>
16
+ <td><%= link_to 'Edit', edit_person_path(person) %></td>
17
+ <td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
18
+ </tr>
19
+ <% end %>
20
+ </table>
21
+
22
+ <br />
23
+
24
+ <%= link_to 'New person', new_person_path %>
@@ -0,0 +1,26 @@
1
+ <h1>New person</h1>
2
+
3
+ <%= error_messages_for :person %>
4
+
5
+ <% form_for(@person) do |f| %>
6
+ <p>
7
+ <b>Name</b><br />
8
+ <%= f.text_field :name %>
9
+ </p>
10
+
11
+ <p>
12
+ <b>Address</b><br />
13
+ <%= f.text_area :address %>
14
+ </p>
15
+
16
+ <p>
17
+ <b>Age</b><br />
18
+ <%= f.text_field :age %>
19
+ </p>
20
+
21
+ <p>
22
+ <%= f.submit "Create" %>
23
+ </p>
24
+ <% end %>
25
+
26
+ <%= link_to 'Back', people_path %>
@@ -0,0 +1,18 @@
1
+ <p>
2
+ <b>Name:</b>
3
+ <%=h @person.name %>
4
+ </p>
5
+
6
+ <p>
7
+ <b>Address:</b>
8
+ <%=h @person.address %>
9
+ </p>
10
+
11
+ <p>
12
+ <b>Age:</b>
13
+ <%=h @person.age %>
14
+ </p>
15
+
16
+
17
+ <%= link_to 'Edit', edit_person_path(@person) %> |
18
+ <%= link_to 'Back', people_path %>
@@ -0,0 +1,109 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ # FIXME : Ruby 1.9
28
+ def preinitialize
29
+ load(preinitializer_path) if File.exists?(preinitializer_path)
30
+ end
31
+
32
+ def preinitializer_path
33
+ "#{RAILS_ROOT}/config/preinitializer.rb"
34
+ end
35
+ end
36
+
37
+ class Boot
38
+ def run
39
+ load_initializer
40
+ Rails::Initializer.run(:set_load_path)
41
+ end
42
+ end
43
+
44
+ class VendorBoot < Boot
45
+ def load_initializer
46
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
47
+ end
48
+ end
49
+
50
+ class GemBoot < Boot
51
+ def load_initializer
52
+ self.class.load_rubygems
53
+ load_rails_gem
54
+ require 'initializer'
55
+ end
56
+
57
+ def load_rails_gem
58
+ if version = self.class.gem_version
59
+ gem 'rails', version
60
+ else
61
+ gem 'rails'
62
+ end
63
+ rescue Gem::LoadError => load_error
64
+ $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.)
65
+ exit 1
66
+ end
67
+
68
+ class << self
69
+ def rubygems_version
70
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
71
+ end
72
+
73
+ def gem_version
74
+ if defined? RAILS_GEM_VERSION
75
+ RAILS_GEM_VERSION
76
+ elsif ENV.include?('RAILS_GEM_VERSION')
77
+ ENV['RAILS_GEM_VERSION']
78
+ else
79
+ parse_gem_version(read_environment_rb)
80
+ end
81
+ end
82
+
83
+ def load_rubygems
84
+ require 'rubygems'
85
+
86
+ unless rubygems_version >= '0.9.4'
87
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
88
+ exit 1
89
+ end
90
+
91
+ rescue LoadError
92
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
93
+ exit 1
94
+ end
95
+
96
+ def parse_gem_version(text)
97
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
98
+ end
99
+
100
+ private
101
+ def read_environment_rb
102
+ File.read("#{RAILS_ROOT}/config/environment.rb")
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ # All that for this:
109
+ Rails.boot!
@@ -0,0 +1,19 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ timeout: 5000
7
+
8
+ # Warning: The database defined as 'test' will be erased and
9
+ # re-generated from your development database when you run 'rake'.
10
+ # Do not set this db to the same as development or production.
11
+ test:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ timeout: 5000
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: db/production.sqlite3
19
+ timeout: 5000
@@ -0,0 +1,13 @@
1
+ RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
2
+
3
+ require File.join(File.dirname(__FILE__), 'boot')
4
+
5
+ Rails::Initializer.run do |config|
6
+ config.action_controller.session = {
7
+ :session_key => '_test_session',
8
+ :secret => '5b230be6567e2558f51e2ce60441b836d2621d37a4f868036a1817ec941f2e773965df720f7516027c3f729ca6321b37e42160307519f5592b7e283fb16f0d44'
9
+ }
10
+ config.after_initialize do
11
+ config.extenstions = [:respond_to, :lazy_attributes, :console]
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_extensions = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,19 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Use a different logger for distributed setups
8
+ # config.logger = SyslogLogger.new
9
+
10
+ # Full error reports are disabled and caching is turned on
11
+ config.action_controller.consider_all_requests_local = false
12
+ config.action_controller.perform_caching = true
13
+ config.action_view.cache_template_loading = true
14
+
15
+ # Enable serving of images, stylesheets, and javascripts from an asset server
16
+ # config.action_controller.asset_host = "http://assets.example.com"
17
+
18
+ # Disable delivery errors, bad email addresses will be ignored
19
+ # config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,22 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Disable request forgery protection in test environment
17
+ config.action_controller.allow_forgery_protection = false
18
+
19
+ # Tell ActionMailer not to deliver emails to the real world.
20
+ # The :test delivery method accumulates sent emails in the
21
+ # ActionMailer::Base.deliveries array.
22
+ config.action_mailer.delivery_method = :test
@@ -0,0 +1,4 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.resources :people
3
+ map.root :controller => 'people'
4
+ end
@@ -0,0 +1,15 @@
1
+ class CreatePeople < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :people do |t|
4
+ t.string :name
5
+ t.text :address
6
+ t.integer :age
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :people
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class AddStuffToPerson < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :people, :bio, :text
4
+ add_column :people, :history, :text
5
+ end
6
+
7
+ def self.down
8
+ remove_column :people, :history
9
+ remove_column :people, :bio
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # This file is auto-generated from the current state of the database. Instead of editing this file,
2
+ # please use the migrations feature of ActiveRecord to incrementally modify your database, and
3
+ # then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6
+ # to create the application database on another system, you should be using db:schema:load, not running
7
+ # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
9
+ #
10
+ # It's strongly recommended to check this file into your version control system.
11
+
12
+ ActiveRecord::Schema.define(:version => 2) do
13
+
14
+ create_table "people", :force => true do |t|
15
+ t.string "name"
16
+ t.text "address"
17
+ t.integer "age"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ t.text "bio"
21
+ t.text "history"
22
+ end
23
+
24
+ end
Binary file
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,10 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
+
5
+ # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
6
+ # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
+ require "dispatcher"
8
+
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
+ Dispatcher.dispatch
@@ -0,0 +1,24 @@
1
+ #!/opt/local/bin/ruby
2
+ #
3
+ # You may specify the path to the FastCGI crash log (a log of unhandled
4
+ # exceptions which forced the FastCGI instance to exit, great for debugging)
5
+ # and the number of requests to process before running garbage collection.
6
+ #
7
+ # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
8
+ # and the GC period is nil (turned off). A reasonable number of requests
9
+ # could range from 10-100 depending on the memory footprint of your app.
10
+ #
11
+ # Example:
12
+ # # Default log path, normal GC behavior.
13
+ # RailsFCGIHandler.process!
14
+ #
15
+ # # Default log path, 50 requests between GC.
16
+ # RailsFCGIHandler.process! nil, 50
17
+ #
18
+ # # Custom log path, normal GC behavior.
19
+ # RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'
20
+ #
21
+ require File.dirname(__FILE__) + "/../config/environment"
22
+ require 'fcgi_handler'
23
+
24
+ RailsFCGIHandler.process!
@@ -0,0 +1,10 @@
1
+ #!/opt/local/bin/ruby
2
+
3
+ require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
4
+
5
+ # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
6
+ # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
7
+ require "dispatcher"
8
+
9
+ ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
10
+ Dispatcher.dispatch
File without changes
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/about'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/destroy'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/benchmarker'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/profiler'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/performance/request'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/plugin'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/inspector'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/reaper'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../../config/boot'
3
+ require 'commands/process/spawner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/runner'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/server'
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ one:
4
+ name: MyString
5
+ address: MyText
6
+ age: 1
7
+
8
+ two:
9
+ name: MyString
10
+ address: MyText
11
+ age: 1
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class PeopleControllerTest < ActionController::TestCase
4
+ def test_should_get_index
5
+ get :index
6
+ assert_response :success
7
+ assert_not_nil assigns(:people)
8
+ end
9
+
10
+ def test_should_get_new
11
+ get :new
12
+ assert_response :success
13
+ end
14
+
15
+ def test_should_create_person
16
+ assert_difference('Person.count') do
17
+ post :create, :person => { :name => 'lifo', :address => 'lala land', :age => 420 }
18
+ end
19
+
20
+ assert_redirected_to person_path(assigns(:person))
21
+ end
22
+
23
+ def test_should_show_person
24
+ get :show, :id => people(:one).id
25
+ assert_response :success
26
+ end
27
+
28
+ def test_should_get_edit
29
+ get :edit, :id => people(:one).id
30
+ assert_response :success
31
+ end
32
+
33
+ def test_should_update_person
34
+ put :update, :id => people(:one).id, :person => { }
35
+ assert_redirected_to person_path(assigns(:person))
36
+ end
37
+
38
+ def test_should_destroy_person
39
+ assert_difference('Person.count', -1) do
40
+ delete :destroy, :id => people(:one).id
41
+ end
42
+
43
+ assert_redirected_to people_path
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class Test::Unit::TestCase
6
+ self.use_transactional_fixtures = true
7
+ self.use_instantiated_fixtures = false
8
+
9
+ fixtures :all
10
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class PersonTest < ActiveSupport::TestCase
4
+ def setup
5
+ super
6
+ @person = Person.find :first
7
+ @lazy = ['history', 'bio'].to_set
8
+ @columns = Person.column_names.to_set - ['id']
9
+ end
10
+
11
+ def test_lazy_attributes_values
12
+ assert_equal @lazy, @person.class.lazy_attributes
13
+ end
14
+
15
+ def test_quoted_attributes_should_include_all_columns
16
+ assert_equal @columns, @person.send(:attributes_with_quotes).keys.to_set.delete('id')
17
+ end
18
+
19
+ def test_quoted_attributes_should_exclude_lazy_columns_for_updates
20
+ assert_equal @columns - @lazy, attr_for_update(@person)
21
+ end
22
+
23
+ def test_changed_lazy_attributes_behave_well
24
+ @person.name = "Whatever"
25
+ assert_equal @columns - @lazy, attr_for_update(@person)
26
+
27
+ @person.bio = "Hello world"
28
+ assert_equal @columns - ['history'], attr_for_update(@person)
29
+
30
+ @person.history = "Nothing."
31
+ assert_equal @columns, attr_for_update(@person)
32
+
33
+ assert @person.save!
34
+ @person.reload
35
+
36
+ assert_equal "Nothing.", @person.history
37
+ assert_equal "Whatever", @person.name
38
+ end
39
+
40
+ def test_save_clears_lazy_data
41
+ @person.bio = "DSL"
42
+ assert_equal @columns - ['history'], attr_for_update(@person)
43
+
44
+ assert @person.save
45
+ assert_equal @columns - @lazy, attr_for_update(@person)
46
+ assert_equal "DSL", @person.bio
47
+ end
48
+
49
+ def test_reload_clears_lazy_data
50
+ @person.bio = "Shenanigans"
51
+ @person.history = "Bloody"
52
+ assert_equal @columns, attr_for_update(@person)
53
+
54
+ assert @person.reload
55
+
56
+ assert_equal @columns - @lazy, attr_for_update(@person)
57
+ end
58
+
59
+ private
60
+
61
+ def attr_for_update(person)
62
+ person.send(:attributes_with_quotes, false, false).keys.to_set
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railsex
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.2"
5
+ platform: ruby
6
+ authors:
7
+ - ""
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-12-20 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: ""
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - CHANGELOG
26
+ - init.rb
27
+ - lib/actionpack/mime_responds_extension.rb
28
+ - lib/activerecord/changed.rb
29
+ - lib/railties/console.rb
30
+ - LICENSE
31
+ - Manifest
32
+ - README
33
+ - test/app/controllers/application.rb
34
+ - test/app/controllers/people_controller.rb
35
+ - test/app/helpers/application_helper.rb
36
+ - test/app/helpers/people_helper.rb
37
+ - test/app/models/person.rb
38
+ - test/app/views/layouts/application.html.erb
39
+ - test/app/views/people/edit.html.erb
40
+ - test/app/views/people/index.html.erb
41
+ - test/app/views/people/new.html.erb
42
+ - test/app/views/people/show.html.erb
43
+ - test/config/boot.rb
44
+ - test/config/database.yml
45
+ - test/config/environment.rb
46
+ - test/config/environments/development.rb
47
+ - test/config/environments/production.rb
48
+ - test/config/environments/test.rb
49
+ - test/config/routes.rb
50
+ - test/db/development.sqlite3
51
+ - test/db/migrate/001_create_people.rb
52
+ - test/db/migrate/002_add_stuff_to_person.rb
53
+ - test/db/schema.rb
54
+ - test/db/test.sqlite3
55
+ - test/public/404.html
56
+ - test/public/422.html
57
+ - test/public/500.html
58
+ - test/public/dispatch.cgi
59
+ - test/public/dispatch.fcgi
60
+ - test/public/dispatch.rb
61
+ - test/public/favicon.ico
62
+ - test/Rakefile
63
+ - test/script/about
64
+ - test/script/console
65
+ - test/script/destroy
66
+ - test/script/generate
67
+ - test/script/performance/benchmarker
68
+ - test/script/performance/profiler
69
+ - test/script/performance/request
70
+ - test/script/plugin
71
+ - test/script/process/inspector
72
+ - test/script/process/reaper
73
+ - test/script/process/spawner
74
+ - test/script/runner
75
+ - test/script/server
76
+ - test/test/fixtures/people.yml
77
+ - test/test/functional/people_controller_test.rb
78
+ - test/test/test_helper.rb
79
+ - test/test/unit/person_test.rb
80
+ - railsex.gemspec
81
+ has_rdoc: true
82
+ homepage: ""
83
+ post_install_message:
84
+ rdoc_options: []
85
+
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project: railsex
103
+ rubygems_version: 0.9.5
104
+ signing_key:
105
+ specification_version: 2
106
+ summary: ""
107
+ test_files:
108
+ - test/test/test_helper.rb