activeadmin_associations 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/.coveralls.yml +1 -0
  2. data/.gitignore +57 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +9 -0
  6. data/MIT_LICENSE.txt +20 -0
  7. data/README.md +220 -0
  8. data/Rakefile +20 -0
  9. data/activeadmin_associations.gemspec +32 -0
  10. data/app/controllers/autocomplete_controller.rb +37 -0
  11. data/app/helpers/active_admin_associations_helper.rb +77 -0
  12. data/app/views/admin/shared/_add_to_association.html.erb +21 -0
  13. data/app/views/admin/shared/_association_collection_table_actions.html.erb +4 -0
  14. data/app/views/admin/shared/_blank_slate.html.erb +3 -0
  15. data/app/views/admin/shared/_collection_table.html.erb +58 -0
  16. data/app/views/admin/shared/_form.html.erb +7 -0
  17. data/config/routes.rb +7 -0
  18. data/lib/active_admin_associations/active_admin_extensions.rb +17 -0
  19. data/lib/active_admin_associations/association_actions.rb +77 -0
  20. data/lib/active_admin_associations/association_config.rb +50 -0
  21. data/lib/active_admin_associations/autocompleter.rb +61 -0
  22. data/lib/active_admin_associations/engine.rb +23 -0
  23. data/lib/active_admin_associations/form_config_dsl.rb +15 -0
  24. data/lib/active_admin_associations/redirect_destroy_actions.rb +7 -0
  25. data/lib/active_admin_associations/version.rb +3 -0
  26. data/lib/activeadmin_associations.rb +20 -0
  27. data/lib/formtastic/inputs/token_input.rb +43 -0
  28. data/lib/formtastic/token_input_default_for_association.rb +19 -0
  29. data/spec/association_config_spec.rb +41 -0
  30. data/spec/autocompleter_spec.rb +58 -0
  31. data/spec/controllers/admin_posts_controller_spec.rb +87 -0
  32. data/spec/controllers/autocomplete_controller_spec.rb +36 -0
  33. data/spec/dummy/README.rdoc +261 -0
  34. data/spec/dummy/Rakefile +7 -0
  35. data/spec/dummy/app/admin/dashboards.rb +33 -0
  36. data/spec/dummy/app/admin/posts.rb +20 -0
  37. data/spec/dummy/app/admin/tags.rb +11 -0
  38. data/spec/dummy/app/assets/javascripts/active_admin.js +8 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  40. data/spec/dummy/app/assets/stylesheets/active_admin.css.scss +6 -0
  41. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  44. data/spec/dummy/app/mailers/.gitkeep +0 -0
  45. data/spec/dummy/app/models/.gitkeep +0 -0
  46. data/spec/dummy/app/models/admin_user.rb +10 -0
  47. data/spec/dummy/app/models/post.rb +11 -0
  48. data/spec/dummy/app/models/tag.rb +15 -0
  49. data/spec/dummy/app/models/tagging.rb +7 -0
  50. data/spec/dummy/app/models/user.rb +8 -0
  51. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  52. data/spec/dummy/config.ru +4 -0
  53. data/spec/dummy/config/application.rb +63 -0
  54. data/spec/dummy/config/boot.rb +10 -0
  55. data/spec/dummy/config/database.yml +19 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +37 -0
  58. data/spec/dummy/config/environments/production.rb +67 -0
  59. data/spec/dummy/config/environments/test.rb +37 -0
  60. data/spec/dummy/config/initializers/active_admin.rb +129 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/devise.rb +218 -0
  63. data/spec/dummy/config/initializers/inflections.rb +15 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  66. data/spec/dummy/config/initializers/session_store.rb +8 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/devise.en.yml +57 -0
  69. data/spec/dummy/config/locales/en.yml +5 -0
  70. data/spec/dummy/config/routes.rb +62 -0
  71. data/spec/dummy/db/.gitignore +1 -0
  72. data/spec/dummy/db/migrate/20120504220404_devise_create_admin_users.rb +52 -0
  73. data/spec/dummy/db/migrate/20120504221534_create_posts.rb +12 -0
  74. data/spec/dummy/db/migrate/20120504221936_create_users.rb +9 -0
  75. data/spec/dummy/db/migrate/20120504222040_create_tags.rb +8 -0
  76. data/spec/dummy/db/migrate/20120504222247_create_taggings.rb +10 -0
  77. data/spec/dummy/db/schema.rb +65 -0
  78. data/spec/dummy/lib/assets/.gitkeep +0 -0
  79. data/spec/dummy/public/404.html +26 -0
  80. data/spec/dummy/public/422.html +26 -0
  81. data/spec/dummy/public/500.html +25 -0
  82. data/spec/dummy/public/favicon.ico +0 -0
  83. data/spec/dummy/script/rails +6 -0
  84. data/spec/dummy/test/unit/admin_user_test.rb +7 -0
  85. data/spec/dummy/test/unit/post_test.rb +7 -0
  86. data/spec/dummy/test/unit/tag_test.rb +7 -0
  87. data/spec/dummy/test/unit/tagging_test.rb +7 -0
  88. data/spec/dummy/test/unit/user_test.rb +7 -0
  89. data/spec/factories/admin_users.rb +9 -0
  90. data/spec/factories/posts.rb +11 -0
  91. data/spec/factories/taggings.rb +6 -0
  92. data/spec/factories/tags.rb +7 -0
  93. data/spec/factories/users.rb +8 -0
  94. data/spec/features/active_admin_associations_spec.rb +94 -0
  95. data/spec/spec_helper.rb +41 -0
  96. data/spec/support/admin_login_controller_helper.rb +7 -0
  97. data/spec/support/admin_login_integration_helper.rb +8 -0
  98. data/vendor/assets/javascripts/active_admin_associations.js +14 -0
  99. data/vendor/assets/javascripts/jquery.tokeninput.js +915 -0
  100. data/vendor/assets/stylesheets/active_admin_associations.css.scss +18 -0
  101. data/vendor/assets/stylesheets/token-input-facebook.css +121 -0
  102. metadata +383 -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,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,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,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ActiveAdmin Association interface' do
4
+ let!(:post){ Factory(:post) }
5
+ let!(:tag){ Factory(:tag) }
6
+
7
+ before do
8
+ admin_login_as
9
+ post.tags = [tag]
10
+ end
11
+
12
+ describe 'editing a post' do
13
+ before do
14
+ visit "/admin/posts/#{post.id}/edit"
15
+ end
16
+
17
+ it 'has correct inputs from form_columns config' do
18
+ page.should have_selector('form.post fieldset.inputs input#post_title')
19
+ page.should have_selector('form.post fieldset.inputs textarea#post_body')
20
+ page.should have_selector('form.post fieldset.inputs input#post_creator_id')
21
+ end
22
+
23
+ it 'has correct inputs from active_association_form config' do
24
+ page.should have_selector('form.post fieldset#more-inputs input.my-date-picker#post_published_at')
25
+ page.should have_selector('form.post fieldset#more-inputs input#post_featured')
26
+ end
27
+
28
+ it 'has correct token input for post creator' do
29
+ token_input = page.find('form.post fieldset.inputs input.token-input#post_creator_id')
30
+ token_input["type"].should == 'hidden'
31
+ token_input['data-model-name'].should == 'user'
32
+ token_input['value'].should == '1'
33
+ MultiJson.decode(token_input['data-pre']).should == [{"value" => "Bill Tester", "id" => post.creator_id}]
34
+ end
35
+
36
+ it 'has a form to relate new tags' do
37
+ page.should have_selector('.relationship-table#relationship-table-tags form.relate-to-form')
38
+ page.should have_selector('#relationship-table-tags form.relate-to-form input[type="hidden"]#relationship_name')
39
+
40
+ page.find('#relationship-table-tags form.relate-to-form input#relationship_name')['value'].should == 'tags'
41
+
42
+ token_input = page.find('#relationship-table-tags form.relate-to-form input.token-input#related_id')
43
+ token_input['data-model-name'].should == 'tag'
44
+ end
45
+
46
+ it 'has a table of the related tags' do
47
+ page.should have_xpath('//div[@id="relationship-table-tags"]//table[@class="index_table"]/thead//th[text()="Name"]')
48
+
49
+ related_tag_name = page.find(:xpath, "//div[@id='relationship-table-tags']//table[@class='index_table']/tbody//tr[td[1][text()=#{tag.id}]]//td[2]").text
50
+ related_tag_name.should == tag.name
51
+
52
+ edit_link = page.find(:xpath, "//div[@id='relationship-table-tags']//table[@class='index_table']/tbody//tr/td[3]/a[text()='Edit']")
53
+ expect(edit_link['href']).to match(%r{\A/admin/tags/\d+/edit})
54
+
55
+ page.should have_xpath("//div[@id='relationship-table-tags']//table[@class='index_table']/tbody//tr/td[3]/form//input[@type='submit'][@value='Unrelate']")
56
+
57
+ unrelate_form = page.find(:xpath, "//div[@id='relationship-table-tags']//table[@class='index_table']/tbody//tr/td[3]/form[@class='button_to']")
58
+
59
+ unrelate_url = unrelate_form['action']
60
+ expect(unrelate_url).to match(%r{\A/admin/posts/#{post.id}/unrelate})
61
+
62
+ query_params = unrelate_url.split('?')[1].split('&')
63
+ query_params.should =~ ["related_id=#{tag.id}", 'relationship_name=tags']
64
+ end
65
+ end
66
+
67
+ describe 'deleting a post' do
68
+ before do
69
+ visit "/admin/posts"
70
+ end
71
+
72
+ it "redirects back to posts index view" do
73
+ delete_link_tag = page.find('table#index_table_posts tbody tr:first a.delete_link')
74
+ delete_link_tag.click
75
+ current_path.should == "/admin/posts"
76
+ end
77
+ end
78
+
79
+ describe 'editing a tag' do
80
+ before do
81
+ visit "/admin/tags/#{tag.id}/edit"
82
+ end
83
+
84
+ it 'have a table of the related posts' do
85
+ page.should have_xpath('//div[@id="relationship-table-posts"]//table[@class="index_table"]/thead//th[text()="Title"]')
86
+
87
+ post_title_text = page.find(:xpath, "//div[@id='relationship-table-posts']//table[@class='index_table']/tbody//tr[td[1][text()=#{post.id}]]//td[2]").text
88
+ post_title_text.should == post.title
89
+
90
+ post_creator_name = page.find(:xpath, "//div[@id='relationship-table-posts']//table[@class='index_table']/tbody//tr[td[1][text()=#{post.id}]]//td[3]").text
91
+ post_creator_name.should == post.creator.name
92
+ end
93
+ end
94
+ end