Permalink
Browse files

Merge branch 'master' into jquery

Conflicts:

	lib/attribute_fu/associated_form_helper.rb
	test/associated_form_helper_test.rb
  • Loading branch information...
2 parents c83f28d + 2184928 commit adb3a4719c7fdf511255739adff4e3d86a53526b @jamesgolick committed Nov 25, 2008
Showing with 116 additions and 949 deletions.
  1. +4 −1 .gitignore
  2. +7 −1 README → README.rdoc
  3. +1 −0 Rakefile
  4. +13 −0 attribute_fu.gemspec
  5. +7 −4 init.rb
  6. +17 −5 lib/attribute_fu/associations.rb
  7. +0 −10 test/Rakefile
  8. +0 −10 test/app/controllers/application.rb
  9. +0 −3 test/app/helpers/application_helper.rb
  10. +1 −2 test/{test/unit → }/associated_form_helper_test.rb
  11. +1 −1 test/{test/unit → }/comment_test.rb
  12. +0 −97 test/config/boot.rb
  13. +0 −15 test/config/database.yml
  14. +0 −15 test/config/environment.rb
  15. +0 −18 test/config/environments/development.rb
  16. +0 −22 test/config/environments/test.rb
  17. +0 −35 test/config/routes.rb
  18. +1 −0 test/db/.gitignore
  19. +18 −0 test/db/database.yml
  20. +0 −14 test/db/migrate/001_create_photos.rb
  21. +0 −15 test/db/migrate/002_create_comments.rb
  22. +9 −22 test/db/schema.rb
  23. +1 −0 test/log/.gitignore
  24. 0 test/{app → }/models/comment.rb
  25. 0 test/{app → }/models/photo.rb
  26. +12 −1 test/{test/unit → }/photo_test.rb
  27. +0 −3 test/script/console
  28. +0 −3 test/script/destroy
  29. +0 −3 test/script/generate
  30. +0 −3 test/script/server
  31. +0 −6 test/test/test_helper.rb
  32. +24 −0 test/test_helper.rb
  33. +0 −3 test/vendor/plugins/shoulda/init.rb
  34. +0 −20 test/vendor/plugins/shoulda/lib/shoulda.rb
  35. +0 −338 test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb
  36. +0 −143 test/vendor/plugins/shoulda/lib/shoulda/context.rb
  37. +0 −119 test/vendor/plugins/shoulda/lib/shoulda/general.rb
  38. +0 −17 test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb
View
@@ -1 +1,4 @@
-.DS_Store
+.DS_Store
+test/debug.log
+test/db/*.sqlite3
+test/log/*
View
@@ -5,7 +5,7 @@ Creating multi-model forms is amazingly easy with AttributeFu.
= Get It!
- $ piston import http://svn.jamesgolick.com/attribute_fu/tags/stable vendor/plugins/attribute_fu
+ $ script/plugin install git://github.com/giraffesoft/attribute_fu.git
= Conventions
@@ -105,6 +105,12 @@ Come join the discussion on the {mailing list}[link:http://groups.google.com/gro
Updates will be available {here}[http://jamesgolick.com/attribute_fu]
+= Running the tests
+
+To run the tests, you need Shoulda, mocha and multi-rails:
+
+ $ sudo gem install thoughtbot-shoulda --source http://gems.github.com/
+ $ sudo gem install mocha multi_rails
== Credits
View
@@ -1,4 +1,5 @@
require 'rake'
+require "load_multi_rails_rake_tasks"
require 'rake/testtask'
require 'rake/rdoctask'
View
@@ -0,0 +1,13 @@
+Gem::Specification.new do |s|
+ s.name = "attribute_fu"
+ s.version = "0.2.1"
+ s.date = "2008-08-04"
+ s.summary = "rails multi-model forms made easy!"
+ s.email = "james@giraffesoft.ca"
+ s.homepage = "http://jamesgolick.com/attribute_fu"
+ s.description = "Creating multi-model forms is amazingly easy with AttributeFu."
+ s.has_rdoc = true
+ s.authors = ["James Golick"]
+ s.files = ["init.rb", "lib", "lib/attribute_fu", "lib/attribute_fu/associated_form_helper.rb", "lib/attribute_fu/associations.rb", "lib/attribute_fu.rb", "MIT-LICENSE", "Rakefile", "README", "tasks", "tasks/attribute_fu_tasks.rake", "test", "test/app", "test/app/controllers", "test/app/controllers/application.rb", "test/app/helpers", "test/app/helpers/application_helper.rb", "test/app/models", "test/app/models/comment.rb", "test/app/models/photo.rb", "test/config", "test/config/boot.rb", "test/config/database.yml", "test/config/environment.rb", "test/config/environments", "test/config/environments/development.rb", "test/config/environments/test.rb", "test/config/routes.rb", "test/db", "test/db/migrate", "test/db/migrate/001_create_photos.rb", "test/db/migrate/002_create_comments.rb", "test/db/schema.rb", "test/Rakefile", "test/script", "test/script/console", "test/script/destroy", "test/script/generate", "test/script/server", "test/test", "test/test/test_helper.rb", "test/test/unit", "test/test/unit/associated_form_helper_test.rb", "test/test/unit/comment_test.rb", "test/test/unit/photo_test.rb", "test/vendor", "test/vendor/plugins", "test/vendor/plugins/shoulda", "test/vendor/plugins/shoulda/init.rb", "test/vendor/plugins/shoulda/lib", "test/vendor/plugins/shoulda/lib/shoulda", "test/vendor/plugins/shoulda/lib/shoulda/active_record_helpers.rb", "test/vendor/plugins/shoulda/lib/shoulda/context.rb", "test/vendor/plugins/shoulda/lib/shoulda/general.rb", "test/vendor/plugins/shoulda/lib/shoulda/private_helpers.rb", "test/vendor/plugins/shoulda/lib/shoulda.rb", "uninstall.rb"]
+ s.rdoc_options = ["--main", "README"]
+end
View
11 init.rb
@@ -1,7 +1,10 @@
ActiveRecord::Base.class_eval { include AttributeFu::Associations }
ActionView::Helpers::FormBuilder.class_eval { include AttributeFu::AssociatedFormHelper }
-# copy the required javascript file (if it hasn't been copied already)
-target_dir = "#{RAILS_ROOT}/public/javascripts"
-FileUtils.mkdir_p(target_dir) unless File.directory?(target_dir)
-FileUtils.cp(File.join(File.dirname(__FILE__), 'javascripts/jquery.template.js'), "#{RAILS_ROOT}/public/javascripts") unless File.exists?("#{RAILS_ROOT}/public/javascripts/jquery.template.js")
+unless defined?('RAILS_ROOT')
+ # copy the required javascript file (if it hasn't been copied already)
+ target_dir = "#{RAILS_ROOT}/public/javascripts"
+ FileUtils.mkdir_p(target_dir) unless File.directory?(target_dir)
+ FileUtils.cp(File.join(File.dirname(__FILE__), 'javascripts/jquery.template.js'), "#{RAILS_ROOT}/public/javascripts") unless File.exists?("#{RAILS_ROOT}/public/javascripts/jquery.template.js")
+end
+
@@ -62,12 +62,14 @@ def has_many_attributes(association_id, attributes) #:nodoc:
def save_managed_associations #:nodoc:
if managed_association_attributes != nil
managed_association_attributes.keys.each do |association_id|
- association = send(association_id)
- association.each(&:save)
+ if send(association_id).loaded? # don't save what we haven't even loaded
+ association = send(association_id)
+ association.each(&:save)
- unless (objects_to_remove = instance_variable_get removal_variable_name(association_id)).nil?
- objects_to_remove.each { |remove_id| association.delete association.detect { |obj| obj.id.to_s == remove_id.to_s } }
- instance_variable_set removal_variable_name(association_id), nil
+ unless (objects_to_remove = instance_variable_get removal_variable_name(association_id)).nil?
+ objects_to_remove.each { |remove_id| association.delete association.detect { |obj| obj.id.to_s == remove_id.to_s } }
+ instance_variable_set removal_variable_name(association_id), nil
+ end
end
end
end
@@ -114,10 +116,20 @@ def has_many_with_association_option(association_id, options = {}, &extension)
discard_if = discard_if.to_proc if discard_if.is_a?(Symbol)
managed_association_attributes[association_id][:discard_if] = discard_if
end
+ collection_with_attributes_writer(association_id)
end
has_many_without_association_option(association_id, options, &extension)
end
+
+ private
+
+ def collection_with_attributes_writer(association_name)
+ define_method("#{association_name.to_s.singularize}_attributes=") do |attributes|
+ has_many_attributes association_name, attributes
+ end
+ end
+
end
end # Associations
View
@@ -1,10 +0,0 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-
-require(File.join(File.dirname(__FILE__), 'config', 'boot'))
-
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-require 'tasks/rails'
@@ -1,10 +0,0 @@
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
-
- # See ActionController::RequestForgeryProtection for details
- # Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => '012cbaf0c3d36504f3b1bc397b838d24'
-end
@@ -1,3 +0,0 @@
-# Methods added to this helper will be available to all templates in the application.
-module ApplicationHelper
-end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__)+'/../test_helper'
+require File.dirname(__FILE__)+'/test_helper'
class AssociatedFormHelperTest < Test::Unit::TestCase
include ActionView::Helpers::FormHelper
@@ -203,7 +203,6 @@ def setup
end
end
- # context "add associated link with expression parameter" do
# setup do
# comment = @photo.comments.build
#
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/test_helper'
class CommentTest < ActiveSupport::TestCase
should_belong_to :photo
View
@@ -1,97 +0,0 @@
-# Don't change this file!
-# Configure your app in config/environment.rb and config/environments/*.rb
-
-RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
-
-module Rails
- class << self
- def boot!
- pick_boot.run unless booted?
- end
-
- def booted?
- defined? Rails::Initializer
- end
-
- def pick_boot
- (vendor_rails? ? VendorBoot : GemBoot).new
- end
-
- def vendor_rails?
- File.exist?("#{RAILS_ROOT}/vendor/rails")
- end
- end
-
- class Boot
- def run
- load_initializer
- Rails::Initializer.run(:set_load_path)
- end
- end
-
- class VendorBoot < Boot
- def load_initializer
- require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
- end
- end
-
- class GemBoot < Boot
- def load_initializer
- self.class.load_rubygems
- load_rails_gem
- require 'initializer'
- end
-
- def load_rails_gem
- if version = self.class.gem_version
- gem 'rails', "=#{version}"
- else
- gem 'rails'
- end
- rescue Gem::LoadError => load_error
- $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.)
- exit 1
- end
-
- class << self
- def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
- end
-
- def gem_version
- if defined? RAILS_GEM_VERSION
- RAILS_GEM_VERSION
- elsif ENV.include?('RAILS_GEM_VERSION')
- ENV['RAILS_GEM_VERSION']
- else
- parse_gem_version(read_environment_rb)
- end
- end
-
- def load_rubygems
- require 'rubygems'
-
- unless rubygems_version >= '0.9.4'
- $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
- exit 1
- end
-
- rescue LoadError
- $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
- exit 1
- end
-
- def parse_gem_version(text)
- $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([\d.]+)'/
- end
-
- private
- def read_environment_rb
- File.read("#{RAILS_ROOT}/config/environment.rb")
- end
- end
- end
-end
-
-# All that for this:
-Rails.boot!
View
@@ -1,15 +0,0 @@
-development:
- adapter: mysql
- encoding: utf8
- database: attribute_fu_test
- username: root
- password:
- socket: /tmp/mysql.sock
-
-test:
- adapter: mysql
- encoding: utf8
- database: attribute_fu_test
- username: root
- password:
- socket: /tmp/mysql.sock
View
@@ -1,15 +0,0 @@
-$:.reject! { |e| e.include? 'TextMate' }
-RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
-
-require File.join(File.dirname(__FILE__), 'boot')
-
-Rails::Initializer.run do |config|
- config.action_controller.session = {
- :session_key => '_test_session',
- :secret => '012cbaf0c3d36504f3b1bc397b838d24'
- }
-
- config.load_paths += %W( #{RAILS_ROOT}/../lib )
-end
-
-require "#{RAILS_ROOT}/../init"
@@ -1,18 +0,0 @@
-# Settings specified here will take precedence over those in config/environment.rb
-
-# In the development environment your application's code is reloaded on
-# every request. This slows down response time but is perfect for development
-# since you don't have to restart the webserver when you make code changes.
-config.cache_classes = false
-
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
-
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
-config.action_view.cache_template_extensions = false
-config.action_view.debug_rjs = true
-
-# Don't care if the mailer can't send
-config.action_mailer.raise_delivery_errors = false
@@ -1,22 +0,0 @@
-# Settings specified here will take precedence over those in config/environment.rb
-
-# The test environment is used exclusively to run your application's
-# test suite. You never need to work with it otherwise. Remember that
-# your test database is "scratch space" for the test suite and is wiped
-# and recreated between test runs. Don't rely on the data there!
-config.cache_classes = true
-
-# Log error messages when you accidentally call methods on nil.
-config.whiny_nils = true
-
-# Show full error reports and disable caching
-config.action_controller.consider_all_requests_local = true
-config.action_controller.perform_caching = false
-
-# Disable request forgery protection in test environment
-config.action_controller.allow_forgery_protection = false
-
-# Tell ActionMailer not to deliver emails to the real world.
-# The :test delivery method accumulates sent emails in the
-# ActionMailer::Base.deliveries array.
-config.action_mailer.delivery_method = :test
View
@@ -1,35 +0,0 @@
-ActionController::Routing::Routes.draw do |map|
- # The priority is based upon order of creation: first created -> highest priority.
-
- # Sample of regular route:
- # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
- # Keep in mind you can assign values other than :controller and :action
-
- # Sample of named route:
- # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # map.resources :products
-
- # Sample resource route with options:
- # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
-
- # Sample resource route with sub-resources:
- # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
-
- # Sample resource route within a namespace:
- # map.namespace :admin do |admin|
- # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
- # admin.resources :products
- # end
-
- # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
- # map.root :controller => "welcome"
-
- # See how all your routes lay out with "rake routes"
-
- # Install the default routes as the lowest priority.
- map.connect ':controller/:action/:id'
- map.connect ':controller/:action/:id.:format'
-end
View
@@ -0,0 +1 @@
+*.sqlite3
View
@@ -0,0 +1,18 @@
+sqlite3:
+ adapter: sqlite3
+ dbfile: attribute_fu.sqlite3.db
+sqlite3mem:
+ :adapter: sqlite3
+ :dbfile: ":memory:"
+postgresql:
+ :adapter: postgresql
+ :username: postgres
+ :password: postgres
+ :database: attribute_fu_plugin_test
+ :min_messages: ERROR
+mysql:
+ :adapter: mysql
+ :host: localhost
+ :username: root
+ :password:
+ :database: attribute_fu_plugin_test
@@ -1,14 +0,0 @@
-class CreatePhotos < ActiveRecord::Migration
- def self.up
- create_table :photos do |t|
- t.string :title
- t.text :description
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :photos
- end
-end
Oops, something went wrong.

0 comments on commit adb3a47

Please sign in to comment.