aa_associations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +53 -0
  2. data/Gemfile +10 -0
  3. data/MIT_LICENSE.txt +20 -0
  4. data/README.md +213 -0
  5. data/Rakefile +17 -0
  6. data/aa_associations.gemspec +31 -0
  7. data/app/controllers/autocomplete_controller.rb +37 -0
  8. data/app/helpers/active_admin_associations_helper.rb +77 -0
  9. data/app/views/admin/shared/_add_to_association.html.erb +21 -0
  10. data/app/views/admin/shared/_association_collection_table_actions.html.erb +4 -0
  11. data/app/views/admin/shared/_blank_slate.html.erb +3 -0
  12. data/app/views/admin/shared/_collection_table.html.erb +58 -0
  13. data/app/views/admin/shared/_form.html.erb +7 -0
  14. data/config/routes.rb +7 -0
  15. data/lib/aa_associations.rb +20 -0
  16. data/lib/active_admin_associations/active_admin_extensions.rb +13 -0
  17. data/lib/active_admin_associations/association_actions.rb +43 -0
  18. data/lib/active_admin_associations/association_config.rb +50 -0
  19. data/lib/active_admin_associations/autocompleter.rb +64 -0
  20. data/lib/active_admin_associations/engine.rb +25 -0
  21. data/lib/active_admin_associations/form_config_dsl.rb +15 -0
  22. data/lib/active_admin_associations/redirect_destroy_actions.rb +7 -0
  23. data/lib/active_admin_associations/version.rb +3 -0
  24. data/lib/formtastic/inputs/token_input.rb +43 -0
  25. data/lib/formtastic/token_input_default_for_association.rb +19 -0
  26. data/test/active_admin_associations_test.rb +69 -0
  27. data/test/admin_posts_controller_test.rb +52 -0
  28. data/test/association_config_test.rb +43 -0
  29. data/test/autocomplete_controller_test.rb +27 -0
  30. data/test/autocompleter_test.rb +62 -0
  31. data/test/dummy/README.rdoc +261 -0
  32. data/test/dummy/Rakefile +7 -0
  33. data/test/dummy/app/admin/dashboards.rb +44 -0
  34. data/test/dummy/app/admin/posts.rb +20 -0
  35. data/test/dummy/app/admin/tags.rb +11 -0
  36. data/test/dummy/app/assets/javascripts/active_admin.js +8 -0
  37. data/test/dummy/app/assets/javascripts/application.js +15 -0
  38. data/test/dummy/app/assets/stylesheets/active_admin.css.scss +6 -0
  39. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  40. data/test/dummy/app/controllers/application_controller.rb +3 -0
  41. data/test/dummy/app/helpers/application_helper.rb +2 -0
  42. data/test/dummy/app/mailers/.gitkeep +0 -0
  43. data/test/dummy/app/models/.gitkeep +0 -0
  44. data/test/dummy/app/models/admin_user.rb +10 -0
  45. data/test/dummy/app/models/post.rb +11 -0
  46. data/test/dummy/app/models/tag.rb +15 -0
  47. data/test/dummy/app/models/tagging.rb +7 -0
  48. data/test/dummy/app/models/user.rb +8 -0
  49. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  50. data/test/dummy/config.ru +4 -0
  51. data/test/dummy/config/application.rb +63 -0
  52. data/test/dummy/config/boot.rb +10 -0
  53. data/test/dummy/config/database.yml +19 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +37 -0
  56. data/test/dummy/config/environments/production.rb +67 -0
  57. data/test/dummy/config/environments/test.rb +37 -0
  58. data/test/dummy/config/initializers/active_admin.rb +129 -0
  59. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  60. data/test/dummy/config/initializers/devise.rb +216 -0
  61. data/test/dummy/config/initializers/inflections.rb +15 -0
  62. data/test/dummy/config/initializers/mime_types.rb +5 -0
  63. data/test/dummy/config/initializers/secret_token.rb +7 -0
  64. data/test/dummy/config/initializers/session_store.rb +8 -0
  65. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/test/dummy/config/locales/devise.en.yml +57 -0
  67. data/test/dummy/config/locales/en.yml +5 -0
  68. data/test/dummy/config/routes.rb +62 -0
  69. data/test/dummy/db/.gitignore +1 -0
  70. data/test/dummy/db/migrate/20120504220404_devise_create_admin_users.rb +52 -0
  71. data/test/dummy/db/migrate/20120504221534_create_posts.rb +12 -0
  72. data/test/dummy/db/migrate/20120504221936_create_users.rb +9 -0
  73. data/test/dummy/db/migrate/20120504222040_create_tags.rb +8 -0
  74. data/test/dummy/db/migrate/20120504222247_create_taggings.rb +10 -0
  75. data/test/dummy/db/schema.rb +65 -0
  76. data/test/dummy/lib/assets/.gitkeep +0 -0
  77. data/test/dummy/public/404.html +26 -0
  78. data/test/dummy/public/422.html +26 -0
  79. data/test/dummy/public/500.html +25 -0
  80. data/test/dummy/public/favicon.ico +0 -0
  81. data/test/dummy/script/rails +6 -0
  82. data/test/dummy/test/factories/admin_users.rb +9 -0
  83. data/test/dummy/test/factories/posts.rb +11 -0
  84. data/test/dummy/test/factories/taggings.rb +6 -0
  85. data/test/dummy/test/factories/tags.rb +7 -0
  86. data/test/dummy/test/factories/users.rb +8 -0
  87. data/test/dummy/test/unit/admin_user_test.rb +7 -0
  88. data/test/dummy/test/unit/post_test.rb +7 -0
  89. data/test/dummy/test/unit/tag_test.rb +7 -0
  90. data/test/dummy/test/unit/tagging_test.rb +7 -0
  91. data/test/dummy/test/unit/user_test.rb +7 -0
  92. data/test/support/should_change.rb +29 -0
  93. data/test/test_helper.rb +51 -0
  94. data/vendor/assets/javascripts/active_admin_associations.js +14 -0
  95. data/vendor/assets/javascripts/jquery.tokeninput.js +915 -0
  96. data/vendor/assets/stylesheets/active_admin_associations.css.scss +18 -0
  97. data/vendor/assets/stylesheets/token-input-facebook.css +121 -0
  98. metadata +362 -0
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,62 @@
1
+ Dummy::Application.routes.draw do
2
+ ActiveAdmin.routes(self)
3
+
4
+ devise_for :admin_users, ActiveAdmin::Devise.config
5
+
6
+ # The priority is based upon order of creation:
7
+ # first created -> highest priority.
8
+
9
+ # Sample of regular route:
10
+ # match 'products/:id' => 'catalog#view'
11
+ # Keep in mind you can assign values other than :controller and :action
12
+
13
+ # Sample of named route:
14
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
15
+ # This route can be invoked with purchase_url(:id => product.id)
16
+
17
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
18
+ # resources :products
19
+
20
+ # Sample resource route with options:
21
+ # resources :products do
22
+ # member do
23
+ # get 'short'
24
+ # post 'toggle'
25
+ # end
26
+ #
27
+ # collection do
28
+ # get 'sold'
29
+ # end
30
+ # end
31
+
32
+ # Sample resource route with sub-resources:
33
+ # resources :products do
34
+ # resources :comments, :sales
35
+ # resource :seller
36
+ # end
37
+
38
+ # Sample resource route with more complex sub-resources
39
+ # resources :products do
40
+ # resources :comments
41
+ # resources :sales do
42
+ # get 'recent', :on => :collection
43
+ # end
44
+ # end
45
+
46
+ # Sample resource route within a namespace:
47
+ # namespace :admin do
48
+ # # Directs /admin/products/* to Admin::ProductsController
49
+ # # (app/controllers/admin/products_controller.rb)
50
+ # resources :products
51
+ # end
52
+
53
+ # You can have the root of your site routed with "root"
54
+ # just remember to delete public/index.html.
55
+ # root :to => 'welcome#index'
56
+
57
+ # See how all your routes lay out with "rake routes"
58
+
59
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
60
+ # Note: This route will make all actions in every controller accessible via GET requests.
61
+ # match ':controller(/:action(/:id))(.:format)'
62
+ end
@@ -0,0 +1 @@
1
+ *.sqlite3
@@ -0,0 +1,52 @@
1
+ class DeviseCreateAdminUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:admin_users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Encryptable
23
+ # t.string :password_salt
24
+
25
+ ## Confirmable
26
+ # t.string :confirmation_token
27
+ # t.datetime :confirmed_at
28
+ # t.datetime :confirmation_sent_at
29
+ # t.string :unconfirmed_email # Only if using reconfirmable
30
+
31
+ ## Lockable
32
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
33
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
34
+ # t.datetime :locked_at
35
+
36
+ ## Token authenticatable
37
+ # t.string :authentication_token
38
+
39
+
40
+ t.timestamps
41
+ end
42
+
43
+ # Create a default user
44
+ AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
45
+
46
+ add_index :admin_users, :email, :unique => true
47
+ add_index :admin_users, :reset_password_token, :unique => true
48
+ # add_index :admin_users, :confirmation_token, :unique => true
49
+ # add_index :admin_users, :unlock_token, :unique => true
50
+ # add_index :admin_users, :authentication_token, :unique => true
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.integer :creator_id
7
+ t.datetime :published_at
8
+ t.boolean :featured
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class CreateTags < ActiveRecord::Migration
2
+ def change
3
+ create_table :tags do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ class CreateTaggings < ActiveRecord::Migration
2
+ def change
3
+ create_table :taggings do |t|
4
+ t.integer :tag_id, :null => false
5
+ t.string :taggable_type, :null => false
6
+ t.integer :taggable_id, :null => false
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120504222247) do
15
+
16
+ create_table "admin_users", :force => true do |t|
17
+ t.string "email", :default => "", :null => false
18
+ t.string "encrypted_password", :default => "", :null => false
19
+ t.string "reset_password_token"
20
+ t.datetime "reset_password_sent_at"
21
+ t.datetime "remember_created_at"
22
+ t.integer "sign_in_count", :default => 0
23
+ t.datetime "current_sign_in_at"
24
+ t.datetime "last_sign_in_at"
25
+ t.string "current_sign_in_ip"
26
+ t.string "last_sign_in_ip"
27
+ t.datetime "created_at", :null => false
28
+ t.datetime "updated_at", :null => false
29
+ end
30
+
31
+ add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true
32
+ add_index "admin_users", ["reset_password_token"], :name => "index_admin_users_on_reset_password_token", :unique => true
33
+
34
+ create_table "posts", :force => true do |t|
35
+ t.string "title"
36
+ t.text "body"
37
+ t.integer "creator_id"
38
+ t.datetime "published_at"
39
+ t.boolean "featured"
40
+ t.datetime "created_at", :null => false
41
+ t.datetime "updated_at", :null => false
42
+ end
43
+
44
+ create_table "taggings", :force => true do |t|
45
+ t.integer "tag_id", :null => false
46
+ t.string "taggable_type", :null => false
47
+ t.integer "taggable_id", :null => false
48
+ t.datetime "created_at", :null => false
49
+ t.datetime "updated_at", :null => false
50
+ end
51
+
52
+ create_table "tags", :force => true do |t|
53
+ t.string "name"
54
+ t.datetime "created_at", :null => false
55
+ t.datetime "updated_at", :null => false
56
+ end
57
+
58
+ create_table "users", :force => true do |t|
59
+ t.string "name"
60
+ t.string "email"
61
+ t.datetime "created_at", :null => false
62
+ t.datetime "updated_at", :null => false
63
+ end
64
+
65
+ end
File without changes
@@ -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'
@@ -0,0 +1,9 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :admin_user do
5
+ sequence(:email) {|n| "admin#{n}@example.com" }
6
+ password 'BaudP0wer!'
7
+ password_confirmation 'BaudP0wer!'
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :post do
5
+ title "My Great Post"
6
+ body %q{"Keep back!" said several. The crowd swayed a little, and I elbowed my way through. Every one seemed greatly excited. I heard a peculiar humming sound from the pit. "I say!" said Ogilvy; "help keep these idiots back. We don't know what's in the confounded thing, you know!" I saw a young man, a shop assistant in Woking I believe he was, standing on the cylinder and trying to scramble out of the hole again. The crowd had pushed him in. The end of the cylinder was being screwed out from within. Nearly two feet of shining screw projected. Somebody blundered against me, and I narrowly missed being pitched onto the top of the screw. I turned, and as I did so the screw must have come out, for the lid of the cylinder fell upon the gravel with a ringing concussion. I stuck my elbow into the person behind me, and turned my head towards the Thing again. For a moment that circular cavity seemed perfectly black. I had the sunset in my eyes. I think everyone expected to see a man emerge--possibly something a little unlike us terrestrial men, but in}
7
+ published_at 2.days.from_now
8
+ featured false
9
+ association :creator, :factory => :user
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :tagging do
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :tag do
5
+ sequence(:name){|n| "Tag#{n}" }
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :user do
5
+ email "test@example.com"
6
+ name "Bill Tester"
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class AdminUserTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class PostTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TagTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TaggingTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < ActiveSupport::TestCase
4
+ # test "the truth" do
5
+ # assert true
6
+ # end
7
+ end
@@ -0,0 +1,29 @@
1
+ class ActiveSupport::TestCase
2
+ def self.should_change(expression, options = {})
3
+ by, from, to = options.values_at(:by, :from, :to)
4
+ stmt = "change #{expression.inspect}"
5
+ stmt << " from #{from.inspect}" if from
6
+ stmt << " to #{to.inspect}" if to
7
+ stmt << " by #{by.inspect}" if by
8
+
9
+ expression_eval = lambda { eval(expression) }
10
+ before = lambda { @_before_should_change = expression_eval.bind(self).call }
11
+ should stmt, :before => before do
12
+ old_value = @_before_should_change
13
+ new_value = expression_eval.bind(self).call
14
+ assert_operator from, :===, old_value, "#{expression.inspect} did not originally match #{from.inspect}" if from
15
+ assert_not_equal old_value, new_value, "#{expression.inspect} did not change" unless by == 0
16
+ assert_operator to, :===, new_value, "#{expression.inspect} was not changed to match #{to.inspect}" if to
17
+ assert_equal old_value + by, new_value if by
18
+ end
19
+ end
20
+
21
+ def self.should_not_change(expression)
22
+ expression_eval = lambda { eval(expression) }
23
+ before = lambda { @_before_should_not_change = expression_eval.bind(self).call }
24
+ should "not change #{expression.inspect}", :before => before do
25
+ new_value = expression_eval.bind(self).call
26
+ assert_equal @_before_should_not_change, new_value, "#{expression.inspect} changed"
27
+ end
28
+ end
29
+ end