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
@@ -1,29 +0,0 @@
1
- module AktionTestRails
2
- module ClassBuilder
3
- def self.included(example_group)
4
- example_group.class_eval do
5
- after do
6
- teardown_defined_constants
7
- end
8
- end
9
- end
10
-
11
- def define_class(class_name, base = Object, &block)
12
- class_name = class_name.to_s.camelize
13
-
14
- Class.new(base).tap do |constant_class|
15
- Object.const_set(class_name, constant_class)
16
- constant_class.unloadable
17
- constant_class.class_eval(&block) if block_given?
18
- constant_class.reset_column_information if constant_class.respond_to? :reset_column_information
19
- end
20
- end
21
-
22
- def teardown_defined_constants
23
- ActiveSupport::Dependencies.clear
24
- end
25
- end
26
- end
27
-
28
- RSpec.configure {|config| config.include AktionTestRails::ClassBuilder}
29
-
@@ -1,49 +0,0 @@
1
- module AktionTestRails
2
- module Matchers
3
- module FactoryGirl
4
- def have_a_valid_factory(factory_name)
5
- ValidFactoryMatcher.new(factory_name)
6
- end
7
-
8
- class ValidFactoryMatcher
9
- def initialize(factory_name)
10
- @factory_name = factory_name
11
- end
12
-
13
- def matches?(subject)
14
- factory_exists? && factory_creates_valid_record?
15
- end
16
-
17
- def failure_message
18
- message = "Expected :#{@factory_name} to be a valid factory."
19
- if factory_exists?
20
- if @record.errors.full_messages.any?
21
- message << "\n Failed Validations:"
22
- @record.errors.full_messages.each do |error|
23
- message << "\n #{error}"
24
- end
25
- end
26
- else
27
- message << "\n No factory by the name :#{@factory_name} found"
28
- end
29
- message
30
- end
31
-
32
- def description
33
- "has a valid factory named :#{@factory_name}"
34
- end
35
-
36
- protected
37
-
38
- def factory_exists?
39
- ::FactoryGirl.factories.registered?(@factory_name)
40
- end
41
-
42
- def factory_creates_valid_record?
43
- @record = ::FactoryGirl.build(@factory_name)
44
- @record.valid?
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,9 +0,0 @@
1
- if defined?(::ActiveRecord)
2
- if defined?(::FactoryGirl)
3
- require 'aktion_test_rails/matchers/factory_girl'
4
-
5
- module RSpec::Matchers
6
- include AktionTestRails::Matchers::FactoryGirl
7
- end
8
- end
9
- end
@@ -1 +0,0 @@
1
- require 'aktion_test_rails/matchers/integrations/rspec'
@@ -1,70 +0,0 @@
1
- module AktionTestRails
2
- module ModelBuilder
3
- def self.included(example_group)
4
- example_group.class_eval do
5
- before do
6
- @created_tables ||= []
7
- end
8
-
9
- after do
10
- drop_created_tables
11
- end
12
- end
13
- end
14
-
15
- def create_table(table_name, options = {}, &block)
16
- connection = ActiveRecord::Base.connection
17
-
18
- begin
19
- connection.execute("DROP TABLE IF EXISTS #{table_name}")
20
- connection.create_table(table_name, options, &block)
21
- @created_tables << table_name
22
- connection
23
- rescue Exception => e
24
- connection.execute("DROP TABLE IF EXISTS #{table_name}")
25
- raise e
26
- end
27
- end
28
-
29
- def define_model_class(class_name, &block)
30
- define_class(class_name, ActiveRecord::Base, &block)
31
- end
32
-
33
- def define_active_model_class(class_name, options = {}, &block)
34
- define_class(class_name) do
35
- include ActiveModel::Validations
36
-
37
- options[:accessors].each do |column|
38
- attr_accessor column.to_sym
39
- end
40
-
41
- class_eval(&block) if block_given?
42
- end
43
- end
44
-
45
- def define_model(name, columns = {}, &block)
46
- class_name = name.to_s.pluralize.classify
47
- table_name = class_name.tableize
48
-
49
- create_table(table_name) do |table|
50
- columns.each do |name,type|
51
- table.column name, type
52
- end
53
- end
54
-
55
- define_model_class(class_name, &block)
56
- end
57
-
58
- def drop_created_tables
59
- connection = ActiveRecord::Base.connection
60
-
61
- @created_tables.each do |table_name|
62
- connection.execute("DROP TABLE IF EXISTS #{table_name}")
63
- end
64
- end
65
- end
66
- end
67
-
68
- RSpec.configure do |config|
69
- config.include AktionTestRails::ModelBuilder
70
- end
@@ -1,64 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher do
4
- let(:matcher_class) { AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher }
5
-
6
- after(:each) do
7
- FactoryGirl.factories.clear
8
- end
9
-
10
- it "accepts a valid factory" do
11
- define_model :user, :name => :string
12
- FactoryGirl.define do
13
- factory :user do
14
- name "Name"
15
- end
16
- end
17
-
18
- User.new.should have_a_valid_factory(:user)
19
- end
20
-
21
- context "when the factory does not exist" do
22
- before(:each) { define_model :user }
23
-
24
- it "does not accept the factory" do
25
- User.new.should_not have_a_valid_factory(:user)
26
- end
27
-
28
- it "says that the factory does not exist" do
29
- matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
30
- expected_message = <<-ERROR
31
- Expected :user to be a valid factory.
32
- No factory by the name :user found
33
- ERROR
34
- matcher.failure_message.should == expected_message.strip
35
- end
36
- end
37
-
38
- context 'when the factory has validation errors' do
39
- before(:each) do
40
- define_model :user, :name => :string do
41
- validates_presence_of :name
42
- end
43
- FactoryGirl.define do
44
- factory :user do
45
- name nil
46
- end
47
- end
48
- end
49
-
50
- it "does not accept the factory" do
51
- User.new.should_not have_a_valid_factory(:user)
52
- end
53
-
54
- it "should detail validation errors with the factory" do
55
- matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
56
- expected_message = <<-ERROR
57
- Expected :user to be a valid factory.
58
- Failed Validations:
59
- Name can't be blank
60
- ERROR
61
- matcher.failure_message.should == expected_message.strip
62
- end
63
- end
64
- end
data/spec/spec_helper.rb DELETED
@@ -1,27 +0,0 @@
1
- TESTAPP_ROOT = File.join(File.dirname(__FILE__), '..', 'tmp', 'testapp')
2
- FileUtils.rm_rf(TESTAPP_ROOT) if File.exists?(TESTAPP_ROOT)
3
- `rails new #{TESTAPP_ROOT}`
4
-
5
- ENV['RAILS_ENV'] = 'test'
6
- ENV['BUNDLE_GEMFILE'] ||= "#{TESTAPP_ROOT}/Gemfile"
7
-
8
- require "#{TESTAPP_ROOT}/config/environment"
9
- require 'aktion_test_rails'
10
- require 'aktion_test_rails/class_builder'
11
- require 'aktion_test_rails/model_builder'
12
-
13
- PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
14
-
15
- $LOAD_PATH << File.join(PROJECT_ROOT, 'lib')
16
-
17
- Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each{|file| require file}
18
-
19
-
20
- ActiveRecord::Migration.verbose = false
21
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
22
-
23
- RSpec.configure do |config|
24
- config.treat_symbols_as_metadata_keys_with_true_values = true
25
- config.run_all_when_everything_filtered = true
26
- config.order = 'random'
27
- end