Skip to content

Commit

Permalink
Adding initial tests. Probably not enough, but it will do for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Alves Vieira committed Jan 3, 2012
1 parent a26e3c2 commit 2d113a5
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 68 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
source :gemcutter

# Specify your gem's dependencies in awesome_nested_fields.gemspec
gemspec
138 changes: 84 additions & 54 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,78 +1,108 @@
PATH
remote: .
specs:
awesome_nested_fields (0.0.3)
awesome_nested_fields (0.6.0)
rails (>= 3.0.0)

GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.4)
actionpack (= 3.0.4)
mail (~> 2.2.15)
actionpack (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
erubis (~> 2.6.6)
i18n (~> 0.4)
rack (~> 1.2.1)
rack-mount (~> 0.6.13)
rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
activemodel (3.0.4)
activesupport (= 3.0.4)
builder (~> 2.1.2)
i18n (~> 0.4)
activerecord (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
activeresource (3.0.4)
activemodel (= 3.0.4)
activesupport (= 3.0.4)
activesupport (3.0.4)
arel (2.0.8)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
mail (2.2.15)
activesupport (>= 2.3.6)
actionmailer (3.1.3)
actionpack (= 3.1.3)
mail (~> 2.3.0)
actionpack (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.5)
rack-cache (~> 1.1)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.3)
activemodel (3.1.3)
activesupport (= 3.1.3)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.3)
activemodel (= 3.1.3)
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
ansi (1.4.1)
arel (2.2.1)
builder (3.0.0)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
json (1.6.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
mime-types (1.17.2)
multi_json (1.0.4)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.1)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-test (0.5.7)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.0.4)
actionmailer (= 3.0.4)
actionpack (= 3.0.4)
activerecord (= 3.0.4)
activeresource (= 3.0.4)
activesupport (= 3.0.4)
rails (3.1.3)
actionmailer (= 3.1.3)
actionpack (= 3.1.3)
activerecord (= 3.1.3)
activeresource (= 3.1.3)
activesupport (= 3.1.3)
bundler (~> 1.0)
railties (= 3.0.4)
railties (3.0.4)
actionpack (= 3.0.4)
activesupport (= 3.0.4)
railties (= 3.1.3)
railties (3.1.3)
actionpack (= 3.1.3)
activesupport (= 3.1.3)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
treetop (1.4.9)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.24)
turn (0.8.3)
ansi
tzinfo (0.3.31)

PLATFORMS
ruby

DEPENDENCIES
awesome_nested_fields!
bundler (>= 1.0.0)
rspec (>= 2)
turn (~> 0.8.3)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ Contributors

* Chris Parker ([mrcsparker](https://github.com/mrcsparker))
* Juliana Lucena ([julianalucena](https://github.com/julianalucena))

* Rodrigo Vieira ([rodrigoalvesvieira](https://github.com/rodrigoalvesvieira))

TODO
----

* Write tests
* Write more tests
* Make sure it can degrade gracefully
* Implement jQuery autoload
* Make `nested_fields_for` works without a block (looking for partials)
Expand Down
20 changes: 20 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
require 'bundler'
Bundler::GemHelper.install_tasks

# encoding: UTF-8

require 'rake/testtask'
require 'rdoc/task'

task :default => :test

desc 'Run AwesomeNestedFields unit tests.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/*_test.rb'
t.verbose = true
end

require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = '--backtrace --color'
end
4 changes: 3 additions & 1 deletion awesome_nested_fields.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# encoding: utf-8
require File.expand_path('../lib/awesome_nested_fields/version', __FILE__)

Gem::Specification.new do |s|
Expand All @@ -15,6 +15,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = "awesome_nested_fields"

s.add_development_dependency 'bundler', '>= 1.0.0'
s.add_development_dependency 'rspec', '>=2'
s.add_development_dependency 'turn', '~> 0.8.3'
s.add_runtime_dependency 'rails', '>= 3.0.0'

s.files = `git ls-files`.split("\n")
Expand Down
3 changes: 3 additions & 0 deletions lib/awesome_nested_fields.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require "rails" unless defined?(Rails)
require "action_view" unless defined?(ActionView)

module AwesomeNestedFields
if ::Rails.version < '3.1'
require 'awesome_nested_fields/railtie'
Expand Down
10 changes: 2 additions & 8 deletions lib/awesome_nested_fields/railtie.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
module AwesomeNestedFields
class Railtie < ::Rails::Railtie
if Rails.version >= "3.1"
config.before_configuration do
config.action_view.javascript_expansions[:defaults] << 'jquery.nested-fields'
end
else
config.before_configuration do
config.action_view.javascript_expansions[:defaults] << 'jquery.nested-fields.min'
end
config.before_configuration do
config.action_view.javascript_expansions[:defaults] << 'jquery.nested-fields'
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InstallGenerator < ::Rails::Generators::Base

def copy_js
say_status('copying', 'awesome nested fields js file', :green)
copy_file 'jquery.nested-fields.min.js', 'public/javascripts/jquery.nested-fields.min.js'
copy_file 'jquery.nested-fields.js', 'public/javascripts/jquery.nested-fields.js'
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions test/awesome_nested_fields_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'test_helper'

class AwesomeNestedFieldsTest < ActiveSupport::TestCase
test "it has a version" do
version = AwesomeNestedFields::VERSION
assert_match version, /^\d+\.\d+\.\d+$/
assert_not_nil version
end

test "it can escape HTML content" do
escaped_content = AwesomeNestedFields.escape_html_tags("Home > News & Updates")
assert_equal escaped_content, "Home &gt; News &amp; Updates"
end
end
13 changes: 13 additions & 0 deletions test/generators/install_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "test_helper"

class InstallGeneratorTest < Rails::Generators::TestCase
tests InstallGenerator
destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination

test "it creates all files properly" do
run_generator
assert_file "public/javascripts/jquery.nested-fields.js" if Rails.version < "3.1"
end

end
9 changes: 9 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$:.unshift 'lib'

require "rubygems" unless defined?(Gem)
require "rails"
require "awesome_nested_fields"
require "turn"

require "rails/generators/test_case"

0 comments on commit 2d113a5

Please sign in to comment.