rails_action_args 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *~
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yehuda Katz
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.markdown ADDED
@@ -0,0 +1,53 @@
1
+ Not working yet, but close :) Four failing tests.
2
+
3
+ rails-action-args
4
+ ================
5
+
6
+ A plugin for the Rails framework that provides support for arguments to actions that
7
+ come in from the query.
8
+
9
+ ==== Basics
10
+
11
+ {{[
12
+ class Foo < ApplicationController::Base
13
+ def bar(baz)
14
+ bar
15
+ end
16
+ end
17
+ ]}}
18
+
19
+ Hitting "/foo/bar?baz=bat" will call foo("bat").
20
+
21
+ Hitting "/foo/bar" will raise a BadRequest (Status 400) error.
22
+
23
+ ==== Defaults
24
+
25
+ {{[
26
+ class Foo < ApplicationController::Base
27
+ include AbstractController::ActionArgs
28
+ def bar(baz, bat = "hola")
29
+ "#{baz} #{bat}"
30
+ end
31
+ end
32
+ ]}}
33
+
34
+ Hitting "/foo/bar?baz=bat" will call foo("bat", "hola")
35
+
36
+ Hitting "/foo/bar?baz=bat&bat=whaa" will call foo("bat", "whaa")
37
+
38
+ Hitting "/foo/bar" will still raise a BadRequest.
39
+
40
+ ==== Out of order defaults
41
+
42
+ {{[
43
+ class Foo < ApplicationController::Base
44
+ include AbstractController::ActionArgs
45
+ def bar(one, two = "dos", three = "tres")
46
+ "#{one} #{two} #{three}"
47
+ end
48
+ end
49
+ ]}}
50
+
51
+ The interesting thing here is that hitting "/foo/bar?one=uno&three=three" will call
52
+ foo("uno", "dos", "three"). In other words, the defaults can be in any order, and
53
+ rails-action-args will figure out where to fill in the holes.
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rails_action_args"
8
+ gem.summary = %Q{A port of merb-action-args to rails}
9
+ gem.description = %Q{Big thanks to the original authors. Let me know if I missed you. Action args rocks and you deserve the credit :)}
10
+ gem.email = "collintmiller@gmail.com"
11
+ gem.homepage = "http://github.com/collin/rails_action_args"
12
+ gem.authors = [
13
+ "ezmobius",
14
+ "mattetti",
15
+ "maiha",
16
+ "Yehuda Katz",
17
+ "Andy Delcambre",
18
+ "Janne Asmala",
19
+ "Collin Miller"
20
+ ]
21
+ gem.add_dependency "actionpack", ">=3.0.pre"
22
+ gem.add_dependency "ParseTree", ">=3.0.4"
23
+ gem.add_dependency "ruby2ruby", ">=1.2.4"
24
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
+ end
26
+ Jeweler::GemcutterTasks.new
27
+ rescue LoadError
28
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
29
+ end
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ begin
39
+ require 'rcov/rcovtask'
40
+ Rcov::RcovTask.new do |test|
41
+ test.libs << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+ rescue LoadError
46
+ task :rcov do
47
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
48
+ end
49
+ end
50
+
51
+ task :test => :check_dependencies
52
+
53
+ task :default => :test
54
+
55
+ require 'rake/rdoctask'
56
+ Rake::RDocTask.new do |rdoc|
57
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "rails_action_args #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
data/TODO ADDED
File without changes
data/ThankYou ADDED
@@ -0,0 +1,10 @@
1
+ Thanks you to all the developers of merb-action-args. You are totally awesome!
2
+
3
+ ezmobius
4
+ mattetti
5
+ maiha
6
+ Yehuda Katz
7
+ Andy Delcambre
8
+ Janne Asmala
9
+
10
+ Did I miss you?
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/autotest ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/autotest"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/shoulda-2.10.3/bin/convert_to_should_syntax"))
data/bin/erubis ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/erubis-2.6.5/bin/erubis"))
data/bin/multigem ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -w
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/multigem"))
data/bin/multiruby ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -w
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/multiruby"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -w
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/multiruby_setup"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ParseTree-3.0.4/bin/parse_tree_abc"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -w
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ParseTree-3.0.4/bin/parse_tree_audit"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ParseTree-3.0.4/bin/parse_tree_deps"))
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ParseTree-3.0.4/bin/parse_tree_show"))
data/bin/r2r_show ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ruby2ruby-1.2.4/bin/r2r_show"))
data/bin/rackup ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/rack-1.1.0/bin/rackup"))
data/bin/rake ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/rake-0.8.7/bin/rake"))
data/bin/ruby_parse ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -s
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ruby_parser-2.0.4/bin/ruby_parse"))
data/bin/unit_diff ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -ws
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/unit_diff"))
data/bin/zentest ADDED
@@ -0,0 +1,3 @@
1
+ #!/opt/local/bin/ruby -swI .
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
3
+ load File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/gems/ZenTest-4.2.1/bin/zentest"))
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'rails_action_args'
@@ -0,0 +1,50 @@
1
+ require 'rails_action_args/get_args'
2
+ # Marking entire api private because I don't want to think about it right now.
3
+ module AbstractController
4
+ module ActionArgs
5
+ extend ActiveSupport::Concern
6
+ class InvalidActionArgs < StandardError; end
7
+
8
+ included do
9
+ cattr_accessor :action_argument_list
10
+ extend ClassMethods
11
+ end
12
+
13
+ def send_action(action_name)
14
+ send(action_name, *action_args_for(action_name))
15
+ end
16
+
17
+ # :api: private
18
+ def action_args_for(action_name)
19
+ self.class.action_args_for(action_name, params)
20
+ end
21
+
22
+ module ClassMethods
23
+ # :api: private
24
+ def action_args_for(action_name, params)
25
+ self.action_argument_list ||= {}
26
+ action_argument_list[action_name] ||= extract_action_args_for(action_name)
27
+ arguments, defaults = action_argument_list[action_name]
28
+
29
+ arguments.map do |arg, default|
30
+ arg = arg
31
+ param = params.key?(arg.to_sym)
32
+ unless param || (defaults && defaults.include?(arg))
33
+ raise InvalidActionArgs.new("No value or default value supplied for action arg: #{arg}")
34
+ else
35
+ param ? params[arg.to_sym] : default
36
+ end
37
+ end
38
+ end
39
+
40
+ # :api: private
41
+ def extract_action_args_for(action_name)
42
+ args = instance_method(action_name).get_args
43
+ arguments = args[0]
44
+ defaults = []
45
+ arguments.each {|a| defaults << a[0] if a.size == 2} if arguments
46
+ [arguments || [], defaults]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ if RUBY_PLATFORM == "java"
2
+ require File.join(File.dirname(__FILE__), "jruby_args")
3
+ elsif RUBY_VERSION < "1.9"
4
+ require File.join(File.dirname(__FILE__), "mri_args")
5
+ else
6
+ require File.join(File.dirname(__FILE__), "vm_args")
7
+ end
8
+
9
+ class UnboundMethod
10
+ include GetArgs
11
+ end
12
+
13
+ class Method
14
+ include GetArgs
15
+ end
@@ -0,0 +1,67 @@
1
+ require 'java'
2
+ require 'jruby'
3
+
4
+ module GetArgs
5
+ Methods = org.jruby.internal.runtime.methods
6
+
7
+ def get_args
8
+ real_method = JRuby.reference(self)
9
+
10
+ # hack to expose a protected field; could be improved in 1.1.5
11
+ method_field = org.jruby.RubyMethod.java_class.declared_field(:method)
12
+
13
+ method_field.accessible = true
14
+
15
+ dyn_method = method_field.value(real_method)
16
+
17
+ case dyn_method
18
+ when Methods.MethodArgs
19
+ return build_args(dyn_method.args_node)
20
+ else
21
+ raise "Can't get args from method: #{self}"
22
+ end
23
+ end
24
+
25
+ def build_args(args_node)
26
+ args = []
27
+ required = []
28
+ optional = []
29
+
30
+ # required args
31
+ if (args_node.args && args_node.args.size > 0)
32
+ required << args_node.args.child_nodes.map { |arg| [arg.name.to_s.intern] }
33
+ end
34
+
35
+ # optional args
36
+ if (args_node.opt_args && args_node.opt_args.size > 0)
37
+ optional << args_node.opt_args.child_nodes.map do |arg|
38
+ name = arg.name.to_s.intern
39
+ value_node = arg.value_node
40
+ case value_node
41
+ when org.jruby.ast::FixnumNode
42
+ value = value_node.value
43
+ when org.jruby.ast::SymbolNode
44
+ value = value_node.get_symbol(JRuby.runtime)
45
+ when org.jruby.ast::StrNode
46
+ value = value_node.value
47
+ else
48
+ value = nil
49
+ end
50
+ [name, value]
51
+ end
52
+ end
53
+
54
+ first_args = required.first
55
+ optional.first.each {|arg| first_args << arg} if optional.first
56
+
57
+ args = [first_args]
58
+
59
+ rest = args_node.rest_arg_node
60
+ args << (rest ? rest.name.to_s.intern : nil)
61
+
62
+ block = args_node.block_arg_node
63
+ args << (block ? block.name.to_s.intern : nil)
64
+
65
+ args
66
+ end
67
+ end
@@ -0,0 +1,88 @@
1
+ require 'parse_tree'
2
+ require 'ruby2ruby'
3
+
4
+ class ParseTreeArray < Array
5
+ R2R = Object.const_defined?(:Ruby2Ruby) ? Ruby2Ruby : RubyToRuby
6
+
7
+ def self.translate(*args)
8
+ sexp = ParseTree.translate(*args)
9
+ # ParseTree.translate returns [nil] if called on an inherited method, so walk
10
+ # up the inheritance chain to find the class that the method was defined in
11
+ unless sexp.first
12
+ klass = args.first.ancestors.detect do |klass|
13
+ klass.public_instance_methods(false).include?(args.last.to_s)
14
+ end
15
+ sexp = ParseTree.translate(klass, args.last) if klass
16
+ end
17
+ sexp = Unifier.new.process(sexp)
18
+ self.new(sexp)
19
+ end
20
+
21
+ def deep_array_node(type = nil)
22
+ each do |node|
23
+ return ParseTreeArray.new(node) if node.is_a?(Array) && (!type || node[0] == type)
24
+ next unless node.is_a?(Array)
25
+ return ParseTreeArray.new(node).deep_array_node(type)
26
+ end
27
+ nil
28
+ end
29
+
30
+ def arg_nodes
31
+ self[1..-1].inject([]) do |sum,item|
32
+ sum << [item] unless item.is_a?(Array)
33
+ sum
34
+ end
35
+ end
36
+
37
+ def get_args
38
+ if arg_node = deep_array_node(:args)
39
+ # method defined with def keyword
40
+ args = arg_node.arg_nodes
41
+ default_node = arg_node.deep_array_node(:block)
42
+ return [args, []] unless default_node
43
+ else
44
+ # assuming method defined with Module#define_method
45
+ return [[],[]]
46
+ end
47
+
48
+ # if it was defined with def, and we found the default_node,
49
+ # that should bring us back to regularly scheduled programming..
50
+ lasgns = default_node[1..-1]
51
+ lasgns.each do |asgn|
52
+ args.assoc(asgn[1]) << eval(R2R.new.process(asgn[2]))
53
+ end
54
+ [args, (default_node[1..-1].map { |asgn| asgn[1] })]
55
+ end
56
+
57
+ end
58
+
59
+ # Used in mapping controller arguments to the params hash.
60
+ # NOTE: You must have the 'ruby2ruby' gem installed for this to work.
61
+ #
62
+ # ==== Examples
63
+ # # In PostsController
64
+ # def show(id) #=> id is the same as params[:id]
65
+ module GetArgs
66
+
67
+ # ==== Returns
68
+ # Array:: Method arguments and their default values.
69
+ #
70
+ # ==== Examples
71
+ # class Example
72
+ # def hello(one,two="two",three)
73
+ # end
74
+ #
75
+ # def goodbye
76
+ # end
77
+ # end
78
+ #
79
+ # Example.instance_method(:hello).get_args
80
+ # #=> [[:one], [:two, "two"], [:three, "three"]]
81
+ # Example.instance_method(:goodbye).get_args #=> nil
82
+ def get_args
83
+ klass, meth = self.to_s.split(/ /).to_a[1][0..-2].split("#")
84
+ # Remove stupidity for #<Method: Class(Object)#foo>
85
+ klass = $` if klass =~ /\(/
86
+ ParseTreeArray.translate(klass.constantize, meth).get_args
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ module Rails
2
+ module ActionArgs
3
+ class Railtie < Rails::Railtie
4
+ railtie_name :action_args
5
+
6
+ config.after_initialize do |app|
7
+ class << ::ActionController::Base
8
+ include Rails::ActionArgs::AbstractControllerMixin
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ begin
2
+ require "methopara"
3
+ rescue
4
+ puts "make sure you have methora http://github.com/genki/methopara installed if you want to use action args on Ruby 1.9"
5
+ end
6
+
7
+ module GetArgs
8
+ def get_args
9
+ unless respond_to?(:parameters)
10
+ raise NotImplementedError, "Ruby #{RUBY_VERSION} doesn't support #{self.class}#parameters"
11
+ end
12
+
13
+ required = []
14
+ optional = []
15
+
16
+ parameters.each do |(type, name)|
17
+ if type == :opt
18
+ required << [name, nil]
19
+ optional << name
20
+ else
21
+ required << [name]
22
+ end
23
+ end
24
+
25
+ return [required, optional]
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module AbstractController
2
+ autoload :ActionArgs, "rails_action_args/abstract_controller"
3
+ end
@@ -0,0 +1,128 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require 'rack/test'
4
+ require 'action_controller'
5
+ require 'active_support/all'
6
+ require 'rails_action_args'
7
+
8
+ module ExtraActions
9
+ def funky_inherited_method(foo, bar)
10
+ "#{foo} #{bar}"
11
+ end
12
+ end
13
+
14
+ module Awesome
15
+ class NestedActionArgsController < ActionController::Base
16
+ include AbstractController::ActionArgs
17
+ def index(foo)
18
+ foo.to_s
19
+ end
20
+ end
21
+ end
22
+
23
+ class ActionArgsController < ActionController::Base
24
+ include AbstractController::ActionArgs
25
+ include ExtraActions
26
+
27
+ def nada
28
+ render :text => "NADA"
29
+ end
30
+
31
+ def index(foo)
32
+ render :text => foo
33
+ end
34
+
35
+ def multi(foo, bar)
36
+ render :text => "#{foo} #{bar}"
37
+ end
38
+
39
+ def defaults(foo, bar = "bar")
40
+ render :text => "#{foo} #{bar}"
41
+ end
42
+
43
+ def defaults_mixed(foo, bar ="bar", baz = "baz")
44
+ render :text => "#{foo} #{bar} #{baz}"
45
+ end
46
+
47
+ define_method :dynamic_define_method do
48
+ render :text => "mos def"
49
+ end
50
+
51
+ def with_default_nil(foo, bar = nil)
52
+ render :text => "#{foo} #{bar}"
53
+ end
54
+
55
+ end
56
+
57
+ ActionController::Routing::Routes.draw do |map|
58
+ map.connect ':controller/:action/:id'
59
+ end
60
+
61
+ class ActionArgsTest < Test::Unit::TestCase
62
+ include Rack::Test::Methods
63
+ # test "test_not_accidently_introduce_any_methods_as_controller_actions"
64
+
65
+ def app
66
+ Rack::URLMap.new \
67
+ '/awesome_nested_action_args/index' => Awesome::NestedActionArgsController.action(:index),
68
+ '/action_args/nada' => ActionArgsController.action(:nada),
69
+ '/action_args/index' => ActionArgsController.action(:index),
70
+ '/action_args/multi' => ActionArgsController.action(:multi),
71
+ '/action_args/defaults' => ActionArgsController.action(:defaults),
72
+ '/action_args/defaults_mixed' => ActionArgsController.action(:defaults_mixed),
73
+ '/action_args/dynamic_define_method' => ActionArgsController.action(:dynamic_define_method),
74
+ '/action_args/funky_inherited_method' => ActionArgsController.action(:funky_inherited_method),
75
+ '/action_args/with_default_nil' => ActionArgsController.action(:with_default_nil)
76
+ end
77
+
78
+ def test_handle_a_nested_class
79
+ get "/awesome_nested_action_args/index?foo=bar"
80
+ assert_equal "bar", last_response.body
81
+ end
82
+
83
+ def test_handle_no_arguments
84
+ get "/action_args/nada"
85
+ assert_equal "NADA", last_response.body
86
+ end
87
+
88
+ def test_accept_action_arguments
89
+ get "/action_args/index?foo=bar"
90
+ assert_equal "bar", last_response.body
91
+ end
92
+
93
+ def test_accept_multiple_action_arguments
94
+ get "/action_args/multi?foo=bar&bar=baz"
95
+ assert_equal "bar baz", last_response.body
96
+ end
97
+
98
+ def test_handle_defaults_in_action_arguments
99
+ get "/action_args/defaults?foo=bar"
100
+ assert_equal "bar bar", last_response.body
101
+ end
102
+
103
+ def test_handle_out_of_order_defaults
104
+ get "/action_args/defaults_mixed?foo=bar&baz=bar"
105
+ assert_equal "bar bar bar", last_response.body
106
+ end
107
+
108
+ def test_return_bad_request_if_the_arguments_are_not_provided
109
+ assert_raise(AbstractController::ActionArgs::InvalidActionArgs) do
110
+ get "/action_args/index"
111
+ end
112
+ end
113
+
114
+ def test_treat_define_method_actions_as_equal
115
+ get "/action_args/dynamic_define_method"
116
+ assert_equal "mos def", last_response.body
117
+ end
118
+
119
+ def test_inherit_actions_for_use_with_action_arguments
120
+ get "/action_args/funky_inherited_method?foo=bar&bar=baz"
121
+ assert_equal "bar baz", last_response.body
122
+ end
123
+
124
+ def test_handle_nil_defaults
125
+ get "/action_args/with_default_nil?foo=bar"
126
+ assert_equal "bar ", last_response.body
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_action_args
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ezmobius
8
+ - mattetti
9
+ - maiha
10
+ - Yehuda Katz
11
+ - Andy Delcambre
12
+ - Janne Asmala
13
+ - Collin Miller
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-01-31 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: actionpack
23
+ type: :runtime
24
+ version_requirement:
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.pre
30
+ version:
31
+ - !ruby/object:Gem::Dependency
32
+ name: ParseTree
33
+ type: :runtime
34
+ version_requirement:
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.0.4
40
+ version:
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby2ruby
43
+ type: :runtime
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.2.4
50
+ version:
51
+ description: Big thanks to the original authors. Let me know if I missed you. Action args rocks and you deserve the credit :)
52
+ email: collintmiller@gmail.com
53
+ executables:
54
+ - autotest
55
+ - convert_to_should_syntax
56
+ - erubis
57
+ - multigem
58
+ - multiruby
59
+ - multiruby_setup
60
+ - parse_tree_abc
61
+ - parse_tree_audit
62
+ - parse_tree_deps
63
+ - parse_tree_show
64
+ - r2r_show
65
+ - rackup
66
+ - rake
67
+ - ruby_parse
68
+ - unit_diff
69
+ - zentest
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - LICENSE
74
+ - README.markdown
75
+ - TODO
76
+ files:
77
+ - .document
78
+ - .gitignore
79
+ - LICENSE
80
+ - README.markdown
81
+ - Rakefile
82
+ - TODO
83
+ - ThankYou
84
+ - VERSION
85
+ - init.rb
86
+ - lib/rails_action_args.rb
87
+ - lib/rails_action_args/abstract_controller.rb
88
+ - lib/rails_action_args/get_args.rb
89
+ - lib/rails_action_args/jruby_args.rb
90
+ - lib/rails_action_args/mri_args.rb
91
+ - lib/rails_action_args/railtie.rb
92
+ - lib/rails_action_args/vm_args.rb
93
+ - test/test_rails_action_args.rb
94
+ has_rdoc: true
95
+ homepage: http://github.com/collin/rails_action_args
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --charset=UTF-8
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ version:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ requirements: []
116
+
117
+ rubyforge_project:
118
+ rubygems_version: 1.3.5
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: A port of merb-action-args to rails
122
+ test_files:
123
+ - test/test_rails_action_args.rb