token_field 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +181 -0
- data/Rakefile +26 -0
- data/lib/token_field/capybara/dsl.rb +25 -0
- data/lib/token_field/engine.rb +11 -0
- data/lib/token_field/form_builder.rb +150 -0
- data/lib/token_field/version.rb +3 -0
- data/lib/token_field.rb +3 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/stylesheets/application.css +14 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/categories_controller.rb +38 -0
- data/spec/dummy/app/controllers/products_controller.rb +31 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/category.rb +10 -0
- data/spec/dummy/app/models/product.rb +13 -0
- data/spec/dummy/app/models/product_has_category.rb +6 -0
- data/spec/dummy/app/views/categories/_form.html.erb +12 -0
- data/spec/dummy/app/views/categories/edit.html.erb +2 -0
- data/spec/dummy/app/views/categories/index.html.erb +9 -0
- data/spec/dummy/app/views/categories/new.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/products/_form.html.erb +12 -0
- data/spec/dummy/app/views/products/edit.html.erb +2 -0
- data/spec/dummy/app/views/products/index.html.erb +9 -0
- data/spec/dummy/app/views/products/new.html.erb +2 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +11 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20121012100526_create_categories.rb +10 -0
- data/spec/dummy/db/migrate/20121012235444_create_products.rb +9 -0
- data/spec/dummy/db/migrate/20121012235509_create_product_has_categories.rb +10 -0
- data/spec/dummy/db/schema.rb +36 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +2848 -0
- data/spec/dummy/log/test.log +5938 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/assets/BFD/FA0/sprockets%2F956cc6670041848963c189f12a536075 +0 -0
- data/spec/dummy/tmp/cache/assets/C68/F70/sprockets%2F03000591510dc6784ee531c103e66a7a +0 -0
- data/spec/dummy/tmp/cache/assets/C82/490/sprockets%2F2cea86012965b76f28b56b4522099f12 +0 -0
- data/spec/dummy/tmp/cache/assets/C8A/7F0/sprockets%2F4e7378273896b0f7371ca47f4a24128d +0 -0
- data/spec/dummy/tmp/cache/assets/CCB/5D0/sprockets%2F2b021b5261218f4183021778bade6ddd +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/D0F/700/sprockets%2Fb728373cb12011fa141dfc9a8386ef89 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D3E/1E0/sprockets%2Fd3e4a0e0e469d4f2099f2991fc52bd10 +0 -0
- data/spec/dummy/tmp/cache/assets/D4C/880/sprockets%2Fbb9e5647377f244f135f349fc70e7cba +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D63/FB0/sprockets%2Faed0411c9144264bba7519e8cfda37b4 +0 -0
- data/spec/dummy/tmp/cache/assets/D7F/9E0/sprockets%2Fd984f45a60778c3cf14f1df92b0d9e6d +0 -0
- data/spec/dummy/tmp/cache/assets/DA5/100/sprockets%2F7d657d1d3bce59d08ee0cf74f16086ba +0 -0
- data/spec/dummy/tmp/cache/assets/DA7/A00/sprockets%2Fac9acf238820db9d87b3f81c5de1298b +0 -0
- data/spec/dummy/tmp/cache/assets/DAC/370/sprockets%2F03a081dc7732cd2c4cbb10a57caa43ec +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E1A/730/sprockets%2Fa4e8a61e45b4a04eeb1b2fb5f1b90edb +0 -0
- data/spec/dummy/tmp/pids/server.pid +1 -0
- data/spec/factories/factories.rb +11 -0
- data/spec/requests/categories_spec.rb +68 -0
- data/spec/requests/products_spec.rb +70 -0
- data/spec/spec_helper.rb +62 -0
- metadata +352 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
</div>
|
24
|
+
</body>
|
25
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
98860
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Categories" do
|
5
|
+
before(:each) do
|
6
|
+
@category = create(:category, :name => "wood", :parent_id => nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should list categories" do
|
10
|
+
visit categories_path
|
11
|
+
page.should have_content "wood - 0"
|
12
|
+
end
|
13
|
+
|
14
|
+
# version without javascript
|
15
|
+
it "should be possible to add new element without javascript enabled" do
|
16
|
+
visit new_category_path
|
17
|
+
|
18
|
+
fill_in "category_name", :with => "hello"
|
19
|
+
fill_in "category_parent_id", :with => @category.id.to_s
|
20
|
+
click_button "Create Category"
|
21
|
+
|
22
|
+
page.should have_content "wood - 0"
|
23
|
+
page.should have_content "hello - #{@category.id}"
|
24
|
+
|
25
|
+
Category.last.parent.id.should eq @category.id
|
26
|
+
end
|
27
|
+
|
28
|
+
# version with javascript
|
29
|
+
it "should be possible to add new element with javascript enabled", :js => true do
|
30
|
+
visit new_category_path
|
31
|
+
|
32
|
+
fill_in "category_name", :with => "hello"
|
33
|
+
fill_in_token "category_parent_id", :with => "wood"
|
34
|
+
click_button "Create Category"
|
35
|
+
|
36
|
+
page.should have_content "wood - 0"
|
37
|
+
page.should have_content "hello - #{@category.id}"
|
38
|
+
|
39
|
+
Category.last.parent.id.should eq @category.id
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be possible to edit element without javascript" do
|
43
|
+
new_parent = create(:category, :parent_id => nil)
|
44
|
+
category = create(:category, :parent_id => @category.id)
|
45
|
+
|
46
|
+
category.parent.id.should eq @category.id
|
47
|
+
visit edit_category_path(category)
|
48
|
+
|
49
|
+
fill_in "category_parent_id", :with => new_parent.id.to_s
|
50
|
+
click_button "Update Category"
|
51
|
+
|
52
|
+
category.reload.parent.id.should eq new_parent.id
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be possible to edit element with javascript enabled", :js => true do
|
56
|
+
new_parent = create(:category, :name => "new parent", :parent_id => nil)
|
57
|
+
category = create(:category, :parent_id => @category.id)
|
58
|
+
|
59
|
+
category.parent.id.should eq @category.id
|
60
|
+
visit edit_category_path(category)
|
61
|
+
|
62
|
+
clear_token "category_parent_id"
|
63
|
+
fill_in_token "category_parent_id", :with => "new parent"
|
64
|
+
click_button "Update Category"
|
65
|
+
|
66
|
+
category.reload.parent.id.should eq new_parent.id
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe "Products" do
|
5
|
+
before(:each) do
|
6
|
+
@shoes = create(:category, :name => "shoes")
|
7
|
+
@skirt = create(:category, :name => "skirt")
|
8
|
+
@pents = create(:category, :name => "pents")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should list products" do
|
12
|
+
create(:product, :name => "new one", :category_ids => [@shoes.id, @skirt.id])
|
13
|
+
visit products_path
|
14
|
+
page.should have_content "new one - [#{@shoes.id}, #{@skirt.id}]"
|
15
|
+
end
|
16
|
+
|
17
|
+
# version without javascript
|
18
|
+
it "should be possible to add new element without javascript enabled" do
|
19
|
+
visit new_product_path
|
20
|
+
|
21
|
+
fill_in "product_name", :with => "hello"
|
22
|
+
fill_in "product_category_ids", :with => "#{@pents.id}, #{@shoes.id}"
|
23
|
+
click_button "Create Product"
|
24
|
+
|
25
|
+
page.should have_content "hello - [#{@pents.id}, #{@shoes.id}]"
|
26
|
+
|
27
|
+
Product.last.categories.map(&:id).should eq [@pents.id, @shoes.id]
|
28
|
+
end
|
29
|
+
|
30
|
+
# version with javascript
|
31
|
+
it "should be possible to add new element with javascript enabled", :js => true do
|
32
|
+
visit new_product_path
|
33
|
+
|
34
|
+
fill_in "product_name", :with => "hello"
|
35
|
+
fill_in_token "product_category_ids", :with => "shoes"
|
36
|
+
fill_in_token "product_category_ids", :with => "pents"
|
37
|
+
click_button "Create Product"
|
38
|
+
|
39
|
+
page.should have_content "hello"
|
40
|
+
page.should have_content "hello - [#{@shoes.id}, #{@pents.id}]"
|
41
|
+
|
42
|
+
Product.last.categories.map(&:id).should eq [@shoes.id, @pents.id]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be possible to edit element without javascript" do
|
46
|
+
product = create(:product, :name => "product", :category_ids => [@shoes.id, @pents.id])
|
47
|
+
product.categories.map(&:id).should eq [@shoes.id, @pents.id]
|
48
|
+
|
49
|
+
visit edit_product_path(product)
|
50
|
+
|
51
|
+
fill_in "product_category_ids_#{product.id}", :with => "#{@skirt.id}, #{@shoes.id}"
|
52
|
+
click_button "Update Product"
|
53
|
+
|
54
|
+
product.reload.categories.map(&:id).should eq [@skirt.id, @shoes.id].sort
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be possible to edit element with javascript enabled", :js => true do
|
58
|
+
product = create(:product, :name => "product", :category_ids => [@shoes.id, @pents.id])
|
59
|
+
product.categories.map(&:id).should eq [@shoes.id, @pents.id]
|
60
|
+
|
61
|
+
visit edit_product_path(product)
|
62
|
+
|
63
|
+
clear_token "product_category_ids_#{product.id}"
|
64
|
+
fill_in_token "product_category_ids_#{product.id}", :with => "skirt"
|
65
|
+
fill_in_token "product_category_ids_#{product.id}", :with => "shoes"
|
66
|
+
click_button "Update Product"
|
67
|
+
|
68
|
+
product.reload.categories.map(&:id).sort.should eq [@skirt.id, @shoes.id].sort
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] = 'test'
|
3
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'capybara/rails'
|
7
|
+
require "factory_girl_rails"
|
8
|
+
require "database_cleaner"
|
9
|
+
|
10
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
11
|
+
|
12
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
13
|
+
# in spec/support/ and its subdirectories.
|
14
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each { |f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.filter_run :focus => true
|
18
|
+
config.filter_run_excluding :skip => true
|
19
|
+
#config.filter_run_excluding :js => true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
# ## Mock Framework
|
22
|
+
#
|
23
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
24
|
+
#
|
25
|
+
# config.mock_with :mocha
|
26
|
+
# config.mock_with :flexmock
|
27
|
+
# config.mock_with :rr
|
28
|
+
|
29
|
+
config.include FactoryGirl::Syntax::Methods
|
30
|
+
|
31
|
+
config.include Capybara::DSL
|
32
|
+
config.include TokenField::Capybara::Dsl
|
33
|
+
|
34
|
+
config.before(:each) do
|
35
|
+
DatabaseCleaner.strategy = :truncation
|
36
|
+
DatabaseCleaner.start
|
37
|
+
end
|
38
|
+
|
39
|
+
config.after(:each) do
|
40
|
+
DatabaseCleaner.clean
|
41
|
+
Capybara.reset_sessions!
|
42
|
+
end
|
43
|
+
|
44
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
45
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
46
|
+
|
47
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
48
|
+
# examples within a transaction, remove the following line or assign false
|
49
|
+
# instead of true.
|
50
|
+
#config.use_transactional_fixtures = true
|
51
|
+
|
52
|
+
# If true, the base class of anonymous controllers will be inferred
|
53
|
+
# automatically. This will be the default behavior in future versions of
|
54
|
+
# rspec-rails.
|
55
|
+
# config.infer_base_class_for_anonymous_controllers = false
|
56
|
+
|
57
|
+
# Run specs in random order to surface order dependencies. If you find an
|
58
|
+
# order dependency and want to debug it, you can fix the order by providing
|
59
|
+
# the seed, which is printed after each run.
|
60
|
+
# --seed 1234
|
61
|
+
config.order = "random"
|
62
|
+
end
|