Skip to content

Commit

Permalink
First test rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
David Padilla committed Apr 26, 2011
1 parent f3dbd38 commit 85f7945
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 54 deletions.
43 changes: 0 additions & 43 deletions Gemfile.lock

This file was deleted.

1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -8,4 +8,5 @@ task :default => :test
Rake::TestTask.new do |t|
t.libs << 'test' << 'lib'
t.verbose = true
t.pattern = 'test/**/*_test.rb'
end
2 changes: 1 addition & 1 deletion ajax-nested-fields.gemspec
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|

s.rubyforge_project = "ajax-nested-fields"

s.add_dependency 'actionpack', '~> 3.0.0'
s.add_dependency 'rails', '~> 3.0.0'
s.add_development_dependency "minitest"

s.files = `git ls-files`.split("\n")
Expand Down
5 changes: 2 additions & 3 deletions lib/ajax-nested-fields.rb
@@ -1,11 +1,10 @@
require 'action_view'
require 'ajax-nested-fields/helpers'

# module NestedFields
# def self.included(base)
# base.extend(ClassMethods)
# end
# end

# class ActionView::Base
# include NestedFields
# end
ActionView::Base.send :include, AjaxNestedFields::Helpers
21 changes: 21 additions & 0 deletions lib/ajax-nested-fields/helpers.rb
@@ -0,0 +1,21 @@
module AjaxNestedFields
module Helpers
def just_a_helper
"success"
end

def link_to_remove_fields(name, f, container)
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this, '#{container}')")
end

def link_to_new_child(f, association)
object = f.object.class.reflect_on_association(association.to_sym).klass.new

fields = f.fields_for(association, object, :child_index => "new_#{association.singularize}") do |builder|
render("#{association.singularize}_fields", :f => builder)
end

link_to_function "Add #{association}", h("add_child_field('#{association}', 'new_#{association.singularize}', \"#{escape_javascript(fields)}\")")
end
end
end
28 changes: 28 additions & 0 deletions test/ajax-nested-fields/helpers_test.rb
@@ -0,0 +1,28 @@
require 'test_helper'
require 'action_view/template/handlers/erb'

class Movie
extend ActiveModel::Naming
include ActiveModel::Conversion

def persisted?
false
end

def _destroy

end
end

class HelpersTest < ActionView::TestCase
include AjaxNestedFields::Helpers

def test_link_to_remove_fields
movie = Movie.new
result = form_for movie do |f|
link_to_remove_fields('movie_name', f, 'movies')
end

assert_match result, %r{onclick="remove_fields\(this, 'movies'\); return false;"}
end
end
14 changes: 14 additions & 0 deletions test/test_helper.rb
Expand Up @@ -2,6 +2,20 @@
require 'bundler/setup'
require 'minitest/autorun'

ENV['RAILS_ENV'] ||= 'test'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rails/all'
require 'rails/test_help'
require 'ajax-nested-fields'

module AjaxNestedFields
class Application < Rails::Application; end
end

ActionController::Base.send :include, AjaxNestedFields::Application.routes.url_helpers

AjaxNestedFields::Application.routes.draw do
resources :movies
end
7 changes: 0 additions & 7 deletions test/test_nested-fields.rb

This file was deleted.

0 comments on commit 85f7945

Please sign in to comment.