Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #137 from markburns/master

Refactor of method_missing on Draper::Base for ease of reading
  • Loading branch information...
commit d6e361b206894614db2fd2010740a266a4ef878d 2 parents 051dec8 + c964304
@steveklabnik steveklabnik authored
View
4 Gemfile
@@ -7,7 +7,7 @@ gem 'actionpack', "~> 3.1.3", :require => 'action_view'
gem 'ammeter', '~> 0.2.2', :require => 'ammeter/init'
gem 'guard'
gem 'guard-rspec'
-gem 'launchy'
+gem 'launchy'
gem 'yard'
-gemspec
+gemspec
View
16 Rakefile
@@ -2,31 +2,31 @@ require 'bundler/gem_tasks'
require 'rake'
require 'rspec/core/rake_task'
-RCOV = RUBY_VERSION.to_f == 1.8
+RCOV = RUBY_VERSION.to_f == 1.8
namespace :spec do
-
+
RSpec::Core::RakeTask.new(:coverage) do |t|
t.pattern = 'spec/**/*_spec.rb'
-
- if RCOV
+
+ if RCOV
t.rcov = true
t.rcov_opts = '--exclude osx\/objc,spec,gems\/'
end
end
-
+
RSpec::Core::RakeTask.new(:normal) do |t|
t.pattern ='spec/**/*_spec.rb'
t.rcov = false
end
-
+
namespace :coverage do
desc "Cleanup coverage data"
task :cleanup do
rm_rf 'coverage.data'
rm_rf 'coverage'
end
-
+
desc "Browse the code coverage report."
task :report => ["spec:coverage:cleanup", "spec:coverage"] do
if RCOV
@@ -38,7 +38,7 @@ namespace :spec do
end
end
end
-
+
end
desc "RSpec tests"
View
22 lib/draper/base.rb
@@ -202,19 +202,17 @@ def respond_to?(method, include_private = false)
end
def method_missing(method, *args, &block)
- if allow?(method)
- begin
- self.class.send :define_method, method do |*args, &block|
- model.send(method, *args, &block)
- end
- self.send(method, *args, &block)
- rescue NoMethodError => no_method_error
- super if no_method_error.name == method
- raise no_method_error
- end
- else
- super
+ super unless allow?(method)
+
+ self.class.send :define_method, method do |*args, &block|
+ model.send method, *args, &block
end
+
+ send method, *args, &block
+
+ rescue NoMethodError => no_method_error
+ super if no_method_error.name == method
+ raise no_method_error
end
def self.method_missing(method, *args, &block)
View
4 lib/generators/draper/decorator/decorator_generator.rb
@@ -10,7 +10,7 @@ class DecoratorGenerator < Rails::Generators::Base
argument :resource_name, :type => :string
class_option "test-framework", :type => :string, :default => "rspec", :aliases => "-t", :desc => "Test framework to be invoked"
-
+
source_root File.expand_path('../templates', __FILE__)
DECORATORS_ROOT = 'app/decorators/'
@@ -18,7 +18,7 @@ class DecoratorGenerator < Rails::Generators::Base
def build_model_decorator
template 'decorator.rb', "#{DECORATORS_ROOT}#{resource_name.singularize}_decorator.rb"
end
-#
+
def build_decorator_tests
case options["test-framework"]
when "rspec"
View
5 spec/generators/draper/decorator/decorator_generator_spec.rb
@@ -48,7 +48,6 @@
it { should contain "class ProductDecoratorTest < ActiveSupport::TestCase" }
end
end
-
end
@@ -63,7 +62,7 @@
end
end
-
+
context 'simple' do
before { run_generator %w(products) }
@@ -100,4 +99,4 @@
it { should contain "describe ApplicationDecorator do" }
end
end
-=end
+=end

0 comments on commit d6e361b

Please sign in to comment.
Something went wrong with that request. Please try again.