aktion_test_rails 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +3 -0
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +3 -6
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +18 -3
  6. data/README.md +12 -1
  7. data/Rakefile +2 -8
  8. data/aktion_test_rails.gemspec +1 -4
  9. data/lib/aktion_test_rails/load.rb +18 -0
  10. data/lib/aktion_test_rails/matchers/active_admin/flash.rb +93 -0
  11. data/lib/aktion_test_rails/matchers/active_admin.rb +50 -0
  12. data/lib/aktion_test_rails/matchers/factory_girl/validation.rb +58 -0
  13. data/lib/aktion_test_rails/matchers/factory_girl.rb +7 -2
  14. data/lib/aktion_test_rails/support/active_admin/request/sign_in.rb +17 -0
  15. data/lib/aktion_test_rails/support/active_admin/request.rb +16 -0
  16. data/lib/aktion_test_rails/support/capybara/rack_app.rb +13 -0
  17. data/lib/aktion_test_rails/support/rails/model_builder.rb +59 -0
  18. data/lib/aktion_test_rails/version.rb +1 -1
  19. data/lib/aktion_test_rails.rb +56 -3
  20. data/spec/aktion_test_rails/model_builder_spec.rb +68 -0
  21. data/spec/matchers/active_admin/flash_spec.rb +141 -0
  22. data/spec/matchers/factory_girl/validation_spec.rb +71 -0
  23. data/spec/rails_app/.gitignore +15 -0
  24. data/spec/rails_app/Rakefile +7 -0
  25. data/spec/rails_app/app/admin/admin_user.rb +22 -0
  26. data/spec/rails_app/app/admin/dashboard.rb +33 -0
  27. data/spec/rails_app/app/assets/images/.gitkeep +0 -0
  28. data/spec/rails_app/app/assets/javascripts/active_admin.js +1 -0
  29. data/spec/rails_app/app/assets/javascripts/application.js +15 -0
  30. data/spec/rails_app/app/assets/stylesheets/active_admin.css.scss +29 -0
  31. data/spec/rails_app/app/assets/stylesheets/application.css +13 -0
  32. data/spec/rails_app/app/controllers/application_controller.rb +3 -0
  33. data/spec/rails_app/app/models/admin_user.rb +11 -0
  34. data/spec/rails_app/app/views/layouts/application.html.erb +14 -0
  35. data/spec/rails_app/config/application.rb +19 -0
  36. data/spec/rails_app/config/boot.rb +3 -0
  37. data/spec/rails_app/config/database.yml +5 -0
  38. data/spec/rails_app/config/environment.rb +2 -0
  39. data/spec/rails_app/config/environments/test.rb +37 -0
  40. data/spec/rails_app/config/initializers/active_admin.rb +7 -0
  41. data/spec/rails_app/config/initializers/devise.rb +11 -0
  42. data/spec/rails_app/config/initializers/secret_token.rb +1 -0
  43. data/spec/rails_app/config/initializers/session_store.rb +1 -0
  44. data/spec/rails_app/config/initializers/wrap_parameters.rb +6 -0
  45. data/spec/rails_app/config/locales/devise.en.yml +58 -0
  46. data/spec/rails_app/config/locales/en.yml +9 -0
  47. data/spec/rails_app/config/routes.rb +5 -0
  48. data/spec/rails_app/config.ru +4 -0
  49. data/spec/rails_app/db/migrate/20121126141714_devise_create_admin_users.rb +52 -0
  50. data/spec/rails_app/db/migrate/20121126141717_create_admin_notes.rb +17 -0
  51. data/spec/rails_app/db/migrate/20121126141718_move_admin_notes_to_comments.rb +25 -0
  52. data/spec/rails_app/public/404.html +26 -0
  53. data/spec/rails_app/public/422.html +26 -0
  54. data/spec/rails_app/public/500.html +25 -0
  55. data/spec/rails_app/public/favicon.ico +0 -0
  56. data/spec/rails_app/public/robots.txt +5 -0
  57. data/spec/rails_app/script/rails +6 -0
  58. data/spec/requests/active_admin/sign_in_spec.rb +34 -0
  59. data/spec/spec_active_record.rb +13 -0
  60. data/spec/spec_base.rb +28 -0
  61. data/spec/spec_rails.rb +18 -0
  62. metadata +99 -60
  63. data/Appraisals +0 -15
  64. data/gemfiles/3.0.gemfile +0 -8
  65. data/gemfiles/3.0.gemfile.lock +0 -175
  66. data/gemfiles/3.1.gemfile +0 -10
  67. data/gemfiles/3.1.gemfile.lock +0 -196
  68. data/gemfiles/3.2.gemfile +0 -10
  69. data/gemfiles/3.2.gemfile.lock +0 -194
  70. data/lib/aktion_test_rails/class_builder.rb +0 -29
  71. data/lib/aktion_test_rails/matchers/factory_girl/have_a_valid_factory.rb +0 -49
  72. data/lib/aktion_test_rails/matchers/integrations/rspec.rb +0 -9
  73. data/lib/aktion_test_rails/matchers.rb +0 -1
  74. data/lib/aktion_test_rails/model_builder.rb +0 -70
  75. data/spec/matchers/factory_girl/have_a_valid_factory_spec.rb +0 -64
  76. data/spec/spec_helper.rb +0 -27
@@ -0,0 +1,22 @@
1
+ require "#{Rails.root}/app/models/admin_user"
2
+
3
+ ActiveAdmin.register AdminUser do
4
+ index do
5
+ column :email
6
+ column :current_sign_in_at
7
+ column :last_sign_in_at
8
+ column :sign_in_count
9
+ default_actions
10
+ end
11
+
12
+ filter :email
13
+
14
+ form do |f|
15
+ f.inputs "Admin Details" do
16
+ f.input :email
17
+ f.input :password
18
+ f.input :password_confirmation
19
+ end
20
+ f.buttons
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ ActiveAdmin.register_page "Dashboard" do
2
+
3
+ menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") }
4
+
5
+ content :title => proc{ I18n.t("active_admin.dashboard") } do
6
+ div :class => "blank_slate_container", :id => "dashboard_default_message" do
7
+ span :class => "blank_slate" do
8
+ span "Welcome to Active Admin. This is the default dashboard page."
9
+ small "To add dashboard sections, checkout 'app/admin/dashboards.rb'"
10
+ end
11
+ end
12
+
13
+ # Here is an example of a simple dashboard with columns and panels.
14
+ #
15
+ # columns do
16
+ # column do
17
+ # panel "Recent Posts" do
18
+ # ul do
19
+ # Post.recent(5).map do |post|
20
+ # li link_to(post.title, admin_post_path(post))
21
+ # end
22
+ # end
23
+ # end
24
+ # end
25
+
26
+ # column do
27
+ # panel "Info" do
28
+ # para "Welcome to ActiveAdmin."
29
+ # end
30
+ # end
31
+ # end
32
+ end # content
33
+ end
File without changes
@@ -0,0 +1 @@
1
+ //= require active_admin/base
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,29 @@
1
+ // SASS variable overrides must be declared before loading up Active Admin's styles.
2
+ //
3
+ // To view the variables that Active Admin provides, take a look at
4
+ // `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
5
+ // Active Admin source.
6
+ //
7
+ // For example, to change the sidebar width:
8
+ // $sidebar-width: 242px;
9
+
10
+ // Active Admin's got SASS!
11
+ @import "active_admin/mixins";
12
+ @import "active_admin/base";
13
+
14
+ // Overriding any non-variable SASS must be done after the fact.
15
+ // For example, to change the default status-tag color:
16
+ //
17
+ // body.active_admin {
18
+ // .status_tag { background: #6090DB; }
19
+ // }
20
+ //
21
+ // Notice that Active Admin CSS rules are nested within a
22
+ // 'body.active_admin' selector to prevent conflicts with
23
+ // other pages in the app. It is best to wrap your changes in a
24
+ // namespace so they are properly recognized. You have options
25
+ // if you e.g. want different styles for different namespaces:
26
+ //
27
+ // .active_admin applies to any Active Admin namespace
28
+ // .admin_namespace applies to the admin namespace (eg: /admin)
29
+ // .other_namespace applies to a custom namespace named other (eg: /other)
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,11 @@
1
+ class AdminUser < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :token_authenticatable, :confirmable,
4
+ # :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable,
6
+ :recoverable, :rememberable, :trackable, :validatable
7
+
8
+ # Setup accessible (or protected) attributes for your model
9
+ attr_accessible :email, :password, :password_confirmation, :remember_me
10
+ # attr_accessible :title, :body
11
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Testapp</title>
5
+ <%= stylesheet_link_tag "application", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ if defined?(Bundler)
6
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
7
+ end
8
+
9
+ module Testapp
10
+ class Application < Rails::Application
11
+ config.encoding = "utf-8"
12
+ config.filter_parameters += [:password]
13
+ config.active_support.escape_html_entities_in_json = true
14
+ config.active_record.whitelist_attributes = true
15
+ config.assets.enabled = true
16
+ config.assets.version = '1.0'
17
+ config.active_support.bare = true
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ test:
2
+ adapter: <%= RUBY_PLATFORM =~ /java/ ? 'jdbcsqlite3' : 'sqlite3' %>
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
@@ -0,0 +1,2 @@
1
+ require File.expand_path('../application', __FILE__)
2
+ Testapp::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Testapp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Tell Action Mailer not to deliver emails to the real world.
28
+ # The :test delivery method accumulates sent emails in the
29
+ # ActionMailer::Base.deliveries array.
30
+ config.action_mailer.delivery_method = :test
31
+
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
34
+
35
+ # Print deprecation notices to the stderr
36
+ config.active_support.deprecation = :stderr
37
+ end
@@ -0,0 +1,7 @@
1
+ ActiveAdmin.setup do |config|
2
+ config.site_title = "Testapp"
3
+ config.authentication_method = :authenticate_admin_user!
4
+ config.current_user_method = :current_admin_user
5
+ config.logout_link_path = :destroy_admin_user_session_path
6
+ config.batch_actions = true
7
+ end
@@ -0,0 +1,11 @@
1
+ Devise.setup do |config|
2
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
3
+ require 'devise/orm/active_record'
4
+ config.case_insensitive_keys = [ :email ]
5
+ config.strip_whitespace_keys = [ :email ]
6
+ config.skip_session_storage = [:http_auth]
7
+ config.stretches = Rails.env.test? ? 1 : 10
8
+ config.reconfirmable = true
9
+ config.reset_password_within = 6.hours
10
+ config.sign_out_via = :delete
11
+ end
@@ -0,0 +1 @@
1
+ Testapp::Application.config.secret_token = 'cfe86398ab93c2beecedbeed634b26889127667fc6f6a1468c1bd7721a101d82deefbe93e1cfceeb71007dd640a55e21762e71be6e1631f7c7f1b6480bf2bbdd'
@@ -0,0 +1 @@
1
+ Testapp::Application.config.session_store :cookie_store, key: '_testapp_session'
@@ -0,0 +1,6 @@
1
+ ActiveSupport.on_load(:action_controller) do
2
+ wrap_parameters format: [:json]
3
+ end
4
+ ActiveSupport.on_load(:active_record) do
5
+ self.include_root_in_json = false
6
+ end
@@ -0,0 +1,58 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
32
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
33
+ confirmations:
34
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ send_paranoid_instructions: 'If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
36
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
37
+ registrations:
38
+ signed_up: 'Welcome! You have signed up successfully.'
39
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
40
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
41
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
42
+ updated: 'You updated your account successfully.'
43
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
44
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
45
+ unlocks:
46
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
47
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
48
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
49
+ omniauth_callbacks:
50
+ success: 'Successfully authenticated from %{kind} account.'
51
+ failure: 'Could not authenticate you from %{kind} because "%{reason}".'
52
+ mailer:
53
+ confirmation_instructions:
54
+ subject: 'Confirmation instructions'
55
+ reset_password_instructions:
56
+ subject: 'Reset password instructions'
57
+ unlock_instructions:
58
+ subject: 'Unlock Instructions'
@@ -0,0 +1,9 @@
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"
6
+ active_admin:
7
+ devise:
8
+ login:
9
+ submit: "Login"
@@ -0,0 +1,5 @@
1
+ Testapp::Application.routes.draw do
2
+ ActiveAdmin.routes(self)
3
+
4
+ devise_for :admin_users, ActiveAdmin::Devise.config
5
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Testapp::Application
@@ -0,0 +1,52 @@
1
+ class DeviseCreateAdminUsers < ActiveRecord::Migration
2
+ def migrate(direction)
3
+ super
4
+ # Create a default user
5
+ AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password') if direction == :up
6
+ end
7
+
8
+ def change
9
+ create_table(:admin_users) do |t|
10
+ ## Database authenticatable
11
+ t.string :email, :null => false, :default => ""
12
+ t.string :encrypted_password, :null => false, :default => ""
13
+
14
+ ## Recoverable
15
+ t.string :reset_password_token
16
+ t.datetime :reset_password_sent_at
17
+
18
+ ## Rememberable
19
+ t.datetime :remember_created_at
20
+
21
+ ## Trackable
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
+
28
+ ## Confirmable
29
+ # t.string :confirmation_token
30
+ # t.datetime :confirmed_at
31
+ # t.datetime :confirmation_sent_at
32
+ # t.string :unconfirmed_email # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
36
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
37
+ # t.datetime :locked_at
38
+
39
+ ## Token authenticatable
40
+ # t.string :authentication_token
41
+
42
+
43
+ t.timestamps
44
+ end
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,17 @@
1
+ class CreateAdminNotes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :admin_notes do |t|
4
+ t.string :resource_id, :null => false
5
+ t.string :resource_type, :null => false
6
+ t.references :admin_user, :polymorphic => true
7
+ t.text :body
8
+ t.timestamps
9
+ end
10
+ add_index :admin_notes, [:resource_type, :resource_id]
11
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
12
+ end
13
+
14
+ def self.down
15
+ drop_table :admin_notes
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ class MoveAdminNotesToComments < ActiveRecord::Migration
2
+ def self.up
3
+ remove_index :admin_notes, [:admin_user_type, :admin_user_id]
4
+ rename_table :admin_notes, :active_admin_comments
5
+ rename_column :active_admin_comments, :admin_user_type, :author_type
6
+ rename_column :active_admin_comments, :admin_user_id, :author_id
7
+ add_column :active_admin_comments, :namespace, :string
8
+ add_index :active_admin_comments, [:namespace]
9
+ add_index :active_admin_comments, [:author_type, :author_id]
10
+
11
+ # Update all the existing comments to the default namespace
12
+ say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
13
+ execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
14
+ end
15
+
16
+ def self.down
17
+ remove_index :active_admin_comments, :column => [:author_type, :author_id]
18
+ remove_index :active_admin_comments, :column => [:namespace]
19
+ remove_column :active_admin_comments, :namespace
20
+ rename_column :active_admin_comments, :author_id, :admin_user_id
21
+ rename_column :active_admin_comments, :author_type, :admin_user_type
22
+ rename_table :active_admin_comments, :admin_notes
23
+ add_index :admin_notes, [:admin_user_type, :admin_user_id]
24
+ end
25
+ end