Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added more test and fixed a bug when copy fields type are not text fi…

…elds
  • Loading branch information...
commit 4c33ad4db41307e5665a2531d87cf2c3974bcd52 1 parent 49c6a85
@jiongye authored
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- dynamic_fields (0.1.0)
+ dynamic_fields (0.2.0)
rails (>= 3.1.0)
GEM
View
9 app/assets/javascripts/dynamic_fields/jquery.dynamic_fields.js
@@ -32,7 +32,14 @@
new_name = $(this).attr('name').replace(/\d/, ''+item_num);
$(this).attr('name', new_name);
- $(this).val("");
+ if ($(this)[0].type == 'textarea' || $(this)[0].type == 'text' || $(this)[0].type.match(/select/)){
+ $(this).val("");
+ }else if ($(this)[0].type == 'radio'){
+ $(this).attr("checked", false)
+ }else if ($(this)[0].type == 'checkbox'){
+ $(this).attr("checked", false)
+ }
+
})
item.find('label').each(function(){
View
2  lib/dynamic_fields/version.rb
@@ -1,3 +1,3 @@
module DynamicFields
- VERSION = "0.1.0"
+ VERSION = "0.2.0"
end
View
2  test/dummy/db/migrate/20120329183323_add_test_tables.rb
@@ -17,7 +17,7 @@ def up
t.string :name
end
- create_table :available_languages_subcategories do |t|
+ create_table :available_languages_subcategories, :id => false do |t|
t.integer :subcategory_id
t.integer :available_language_id
end
View
4 test/integration/navigation_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
-class NavigationTest < ActiveSupport::IntegrationCase
+class NavigationTest < ActionDispatch::IntegrationTest
def setup
1.upto(4) { FactoryGirl.create(:available_language) }
@@ -22,6 +22,8 @@ def teardown
visit new_category_path
find("#more_subcategories").click
assert_equal 2, all('fieldset.item').size
+ assert_equal 'true', find('fieldset.item #category_subcategories_attributes_1_active_true')['value']
+ assert_equal find("fieldset.item input[name='category[subcategories_attributes][0][available_language_ids][]']:first")['value'], find("fieldset.item input[name='category[subcategories_attributes][0][available_language_ids][]']:first")['value']
end
test 'create a category with multiple subcategories' do
View
14 test/support/integration_case.rb
@@ -1,14 +0,0 @@
-# Define a bare test case to use with Capybara
-class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
- include Capybara::DSL
- include Rails.application.routes.url_helpers
-
- self.use_transactional_fixtures = false
-
- teardown do
- DatabaseCleaner.clean # Truncate the database
- Capybara.reset_sessions! # Forget the (simulated) browser state
- Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
- end
-
-end
View
23 test/test_helper.rb
@@ -11,10 +11,27 @@
Capybara.default_driver = :rack_test
Capybara.default_selector = :css
-DatabaseCleaner.strategy = :truncation
-
# Run any available migration
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
# Load support files
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
+
+# Transactional fixtures do not work with Selenium tests, because Capybara
+# uses a separate server thread, which the transactions would be hidden
+# from. We hence use DatabaseCleaner to truncate our test database.
+DatabaseCleaner.strategy = :truncation
+
+class ActionDispatch::IntegrationTest
+ # Make the Capybara DSL available in all integration tests
+ include Capybara::DSL
+
+ # Stop ActiveRecord from wrapping tests in transactions
+ self.use_transactional_fixtures = false
+
+ teardown do
+ DatabaseCleaner.clean # Truncate the database
+ Capybara.reset_sessions! # Forget the (simulated) browser state
+ Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.