answers-testing 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a9b8f82fe093a47a91ea6e9bcfbc9b5347910615
4
+ data.tar.gz: 5e5188e1e0fbe80aabf4fbbc5a97ef5147669f0e
5
+ SHA512:
6
+ metadata.gz: 69ef7630de31304a4f63a336e4ade864dcd6485d41041ffe46b6a08a7ed2c4890ba58528404e9d0500cf9d5ca6a53789ecb327044f7fa6f1a50c13b3b3b3217f
7
+ data.tar.gz: 06d7d3f642e0d5972b769b719f2756f425bc843e64df5003dac49b408553501ba7f3c7db85db25b65f157fda7027afe4413c80050bb9bc562398342bfca4de37
@@ -0,0 +1,29 @@
1
+ # Encoding: UTF-8
2
+ require File.expand_path('../../core/lib/answers/version', __FILE__)
3
+
4
+ version = Answers::Version.to_s
5
+
6
+ Gem::Specification.new do |s|
7
+ s.platform = Gem::Platform::RUBY
8
+ s.name = %q{answers-testing}
9
+ s.version = '0.0.0'
10
+ s.summary = %q{Testing plugin for Answers}
11
+ s.description = %q{This plugin adds the ability to test against the Answers CMS gem while inside an Answers extension}
12
+ s.email = ["justin.grevich@gsa.gov", "amos.stone@gsa.gov", "alan.delevie@gsa.gov"]
13
+ s.homepage = %q{https://answers.18f.us}
14
+ s.rubyforge_project = %q{answers}
15
+ s.authors = ['Nick Bristow', 'Alan deLevie', 'Justin Grevich', 'Sasha Magee', 'John Stone', 'Ben Willman', 'John P. Yuda']
16
+ s.license = %q{CC0}
17
+ s.require_paths = %w(lib)
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+
21
+ s.add_dependency 'answers-core'
22
+ s.add_dependency 'database_cleaner', '~> 1.2.0'
23
+ s.add_dependency 'factory_girl_rails', '~> 4.2.1'
24
+ s.add_dependency 'rspec-rails', '~> 3.1.0'
25
+ s.add_dependency 'capybara', '~> 2.4.1'
26
+ s.add_dependency 'capybara-webkit', '~> 1.3.0'
27
+ s.add_dependency 'devise', '~> 3.2.0'
28
+
29
+ end
@@ -0,0 +1 @@
1
+ require 'answers/testing'
@@ -0,0 +1,84 @@
1
+ namespace :answers do
2
+ namespace :testing do
3
+ desc "Generates a dummy app for testing"
4
+ task :dummy_app do
5
+ unless dummy_app_path.exist?
6
+ Rake::Task["answers:testing:setup_dummy_app"].invoke
7
+ Rake::Task["answers:testing:setup_extension"].invoke
8
+ Rake::Task["answers:testing:init_test_database"].invoke
9
+ end
10
+ end
11
+
12
+ task :setup_dummy_app do
13
+ require 'answers-core'
14
+ params = %w(--quiet)
15
+ params << "--database=#{ENV['DB']}" if ENV['DB']
16
+
17
+ Answers::DummyGenerator.start params
18
+
19
+ # Ensure the database is not there from a previous run.
20
+ Rake::Task['answers:testing:drop_dummy_app_database'].invoke
21
+
22
+ Answers::CmsGenerator.start %w[--quiet --fresh-installation]
23
+
24
+ Dir.chdir dummy_app_path
25
+ end
26
+
27
+ # This task is a hook to allow extensions to pass configuration
28
+ # Just define this inside your extension's Rakefile or a .rake file
29
+ # and pass arbitrary code. Example:
30
+ #
31
+ # namespace :answers do
32
+ # namespace :testing do
33
+ # task :setup_extension do
34
+ # require 'answers-my-extension'
35
+ # Answers::MyEngineGenerator.start %w[--quiet]
36
+ # end
37
+ # end
38
+ # end
39
+ task :setup_extension do
40
+ end
41
+
42
+ desc "Remove the dummy app used for testing"
43
+ task :clean_dummy_app do
44
+ Rake::Task['answers:testing:drop_dummy_app_database'].invoke
45
+ dummy_app_path.rmtree if dummy_app_path.exist?
46
+ end
47
+
48
+ desc "Remove the dummy app's database."
49
+ task :drop_dummy_app_database do
50
+ system "bundle exec rake -f #{File.join(dummy_app_path, 'Rakefile')} db:drop"
51
+ end
52
+
53
+ task :init_test_database do
54
+ system "RAILS_ENV=test bundle exec rake -f #{File.join(dummy_app_path, 'Rakefile')} db:{create,migrate}"
55
+ end
56
+
57
+ task :specs do
58
+ paths = Dir.glob('vendor/extensions/*/spec')
59
+ paths << Rails.root
60
+
61
+ status = 0
62
+ paths.each do |path|
63
+ if Rails.root.join(path).basename.to_s == 'spec'
64
+ path = Rails.root.join(path).parent
65
+ end
66
+ cmd = "running specs in #{ path.basename }"
67
+ puts "\n#{ "-" * cmd.to_s.length }\n#{ cmd }\n#{"-" * cmd.to_s.length }"
68
+ Dir.chdir(path) do
69
+ IO.popen("bundle exec bundle install && bundle exec rake answers:testing:dummy_app") unless path == Rails.root
70
+ IO.popen("bundle exec rake spec") do |f|
71
+ f.each { |line| puts line }
72
+ f.close
73
+ status = 1 if $?.to_i > 0
74
+ end
75
+ end
76
+ end
77
+ abort "Some tests failed" if status > 0
78
+ end
79
+
80
+ def dummy_app_path
81
+ Answers::Testing::Railtie.target_extension_path.join('spec', 'dummy')
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,33 @@
1
+ require 'answers-core'
2
+ require 'devise'
3
+ require 'rspec-rails'
4
+ require 'factory_girl_rails'
5
+
6
+ module Answers
7
+ autoload :TestingGenerator, 'generators/answers/testing/testing_generator'
8
+
9
+ module Testing
10
+ class << self
11
+ def root
12
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
13
+ end
14
+
15
+ # Load the factories of all currently loaded extensions
16
+ def load_factories
17
+ Answers.extensions.each do |extension_const|
18
+ if extension_const.respond_to?(:factory_paths)
19
+ extension_const.send(:factory_paths).each do |path|
20
+ FactoryGirl.definition_file_paths << path
21
+ end
22
+ end
23
+ end
24
+ FactoryGirl.find_definitions
25
+ end
26
+ end
27
+
28
+ require 'answers/testing/railtie'
29
+
30
+ autoload :ControllerMacros, 'answers/testing/controller_macros'
31
+ autoload :FeatureMacros, 'answers/testing/feature_macros'
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Answers
2
+ module Testing
3
+ module ControllerMacros
4
+ autoload :Authentication, 'answers/testing/controller_macros/authentication'
5
+ autoload :Methods, 'answers/testing/controller_macros/methods'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,62 @@
1
+ module Answers
2
+ module Testing
3
+ module ControllerMacros
4
+ module Authentication
5
+ def self.extended(base)
6
+ base.send :include, Devise::TestHelpers
7
+ end
8
+
9
+ def answers_login_with(*roles)
10
+ mock_user roles
11
+ end
12
+
13
+ def answers_login_with_factory(factory)
14
+ factory_user factory
15
+ end
16
+
17
+ def mock_user(roles)
18
+ let(:controller_permission) { true }
19
+ roles = handle_deprecated_roles! roles
20
+ let(:logged_in_user) do
21
+ user = double 'Answers::User', :username => 'Joe Fake'
22
+
23
+ roles.each do |role|
24
+ user.stub(:has_role?).with(role).and_return true
25
+ end
26
+ user.stub(:has_role?).with(:superuser).and_return false if roles.exclude? :superuser
27
+
28
+ user
29
+ end
30
+
31
+ before do
32
+ controller.should_receive(:require_answers_users!).and_return false
33
+ controller.should_receive(:authenticate_answers_user!).and_return true
34
+ controller.should_receive(:restrict_plugins).and_return true
35
+ controller.should_receive(:allow_controller?).and_return controller_permission
36
+ controller.stub(:answers_user?).and_return true
37
+ controller.stub(:current_answers_user).and_return logged_in_user
38
+ end
39
+ end
40
+
41
+ def factory_user(factory)
42
+ let(:logged_in_user) { FactoryGirl.create factory }
43
+ before do
44
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
45
+ sign_in logged_in_user
46
+ end
47
+ end
48
+
49
+ private
50
+ def handle_deprecated_roles!(*roles)
51
+ mappings = {
52
+ :user => [],
53
+ :answers_user => [:answers],
54
+ :answers_superuser => [:answers, :superuser],
55
+ :answers_translator => [:answers, :translator]
56
+ }
57
+ mappings[roles.first] || roles
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,37 @@
1
+ module Answers
2
+ module Testing
3
+ module ControllerMacros
4
+ module Methods
5
+ def get(action, options = {})
6
+ process_answers_action(action, 'GET', options)
7
+ end
8
+
9
+ # Executes a request simulating POST HTTP method and set/volley the response
10
+ def post(action, options = {})
11
+ process_answers_action(action, 'POST', options)
12
+ end
13
+
14
+ # Executes a request simulating PUT HTTP method and set/volley the response
15
+ def put(action, options = {})
16
+ process_answers_action(action, 'PUT', options)
17
+ end
18
+
19
+ # Executes a request simulating PATCH HTTP method and set/volley the response
20
+ def patch(action, options = {})
21
+ process_answers_action(action, 'PATCH', options)
22
+ end
23
+
24
+ # Executes a request simulating DELETE HTTP method and set/volley the response
25
+ def delete(action, options = {})
26
+ process_answers_action(action, 'DELETE', options)
27
+ end
28
+
29
+ private
30
+
31
+ def process_answers_action(action, http_method = 'GET', options)
32
+ process(action, http_method, options.merge(:use_route => :answers))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Answers
2
+ module Testing
3
+ module FeatureMacros
4
+ autoload :Authentication, 'answers/testing/feature_macros/authentication'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Answers
2
+ module Testing
3
+ module FeatureMacros
4
+ module Authentication
5
+ def answers_login_with(factory)
6
+ let!(:logged_in_user) { FactoryGirl.create(factory) }
7
+
8
+ before do
9
+ login_as logged_in_user, :scope => :answers_user
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Answers
2
+ module Testing
3
+ class Railtie < Rails::Railtie
4
+ railtie_name :answers_testing
5
+
6
+ class << self
7
+ attr_reader :target_extension_path # :nodoc:
8
+ alias_method :target_engine_path, :target_extension_path
9
+
10
+ # Loads Rake tasks to assist with manipulating dummy applications for testing extensions. Takes
11
+ # a string representing the path to your application or extension.
12
+ #
13
+ # This function should be used in the Rakefile of your application or extension
14
+ #
15
+ # Example:
16
+ # Answers::Testing::Railtie.load_dummy_tasks(File.dirname(__FILE__))
17
+ #
18
+ # Answers::Testing::Railtie.load_dummy_tasks('/users/reset/code/mynew_app')
19
+ def load_dummy_tasks(app_root)
20
+ @target_extension_path = Pathname.new(app_root.to_s)
21
+ load 'answers/tasks/testing.rake'
22
+ end
23
+ end
24
+
25
+ config.after_initialize do
26
+ Answers.register_extension(Answers::Testing)
27
+ Testing.load_factories
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT)
2
+
3
+ # Configure Rails Environment
4
+ ENV["RAILS_ENV"] ||= 'test'
5
+
6
+ require File.expand_path("../../config/environment", __FILE__)
7
+
8
+ require 'rspec/rails'
9
+ require 'capybara/rspec'
10
+
11
+ Rails.backtrace_cleaner.remove_silencers!
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rspec
15
+ config.treat_symbols_as_metadata_keys_with_true_values = true
16
+ config.filter_run :focus => true
17
+ config.run_all_when_everything_filtered = true
18
+ end
19
+
20
+ # Requires supporting files with custom matchers and macros, etc,
21
+ # in ./support/ and its subdirectories including factories.
22
+ ([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | ::Answers::Plugins.registered.pathnames).map{|p|
23
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
24
+ }.flatten.sort.each do |support_file|
25
+ require support_file
26
+ end
@@ -0,0 +1,14 @@
1
+ module Answers
2
+ class TestingGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def rake_db
6
+ rake "answers_testing:install:migrations"
7
+ end
8
+
9
+ def copy_spec_helper
10
+ directory "spec"
11
+ end
12
+
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: answers-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Bristow
8
+ - Alan deLevie
9
+ - Justin Grevich
10
+ - Sasha Magee
11
+ - John Stone
12
+ - Ben Willman
13
+ - John P. Yuda
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2014-09-16 00:00:00.000000000 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: answers-core
21
+ requirement: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: database_cleaner
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.2.0
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.2.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: factory_girl_rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 4.2.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 4.2.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 3.1.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 3.1.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: capybara
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 2.4.1
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 2.4.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: capybara-webkit
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.0
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: devise
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 3.2.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 3.2.0
117
+ description: This plugin adds the ability to test against the Answers CMS gem while
118
+ inside an Answers extension
119
+ email:
120
+ - justin.grevich@gsa.gov
121
+ - amos.stone@gsa.gov
122
+ - alan.delevie@gsa.gov
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - answers-testing.gemspec
128
+ - lib/answers-testing.rb
129
+ - lib/answers/tasks/testing.rake
130
+ - lib/answers/testing.rb
131
+ - lib/answers/testing/controller_macros.rb
132
+ - lib/answers/testing/controller_macros/authentication.rb
133
+ - lib/answers/testing/controller_macros/methods.rb
134
+ - lib/answers/testing/feature_macros.rb
135
+ - lib/answers/testing/feature_macros/authentication.rb
136
+ - lib/answers/testing/railtie.rb
137
+ - lib/generators/answers/testing/templates/spec/spec_helper.rb
138
+ - lib/generators/answers/testing/testing_generator.rb
139
+ homepage: https://answers.18f.us
140
+ licenses:
141
+ - CC0
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project: answers
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Testing plugin for Answers
163
+ test_files: []