refinerycms-testing 1.0.11 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
- --color
1
+ --colour
2
2
  --drb
3
+ --format Fuubar
@@ -0,0 +1,30 @@
1
+ extensions = Dir[File.expand_path('../vendor/extensions/*', __FILE__)]
2
+
3
+ guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
4
+ watch('config/application.rb')
5
+ watch('config/environment.rb')
6
+ watch(%r{^config/environments/.+\.rb$})
7
+ watch(%r{^config/initializers/.+\.rb$})
8
+ watch('spec/spec_helper.rb')
9
+ watch(%r{^spec/support/.+\.rb$})
10
+
11
+ extensions.each do |extension|
12
+ watch(%r{^#{extension}/spec/support/.+\.rb$})
13
+ end
14
+ end
15
+
16
+ guard 'rspec', :version => 2, :spec_paths => extensions.map{|e| "#{e}/spec"},
17
+ :cli => (File.read('.rspec').split("\n").join(' ') if File.exists?('.rspec')) do
18
+ extensions.each do |extension|
19
+ watch(%r{^#{extension}/spec/.+_spec\.rb$})
20
+ watch(%r{^#{extension}/app/(.+)\.rb$}) { |m| "#{extension}/spec/#{m[1]}_spec.rb" }
21
+ watch(%r{^#{extension}/lib/(.+)\.rb$}) { |m| "#{extension}/spec/lib/#{m[1]}_spec.rb" }
22
+ watch(%r{^#{extension}/app/controllers/(.+)_(controller)\.rb$}) { |m| ["#{extension}/spec/routing/#{m[1]}_routing_spec.rb", "#{extension}/spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "#{extension}/spec/requests/#{m[1]}_spec.rb"] }
23
+ watch(%r{^#{extension}/spec/support/(.+)\.rb$}) { "#{extension}/spec" }
24
+ watch("#{extension}/spec/spec_helper.rb") { "#{extension}/spec" }
25
+ watch("#{extension}/config/routes.rb") { "#{extension}/spec/routing" }
26
+ watch("#{extension}/app/controllers/application_controller.rb") { "#{extension}/spec/controllers" }
27
+ # Capybara request specs
28
+ watch(%r{^#{extension}/app/views/(.+)/.*\.(erb|haml)$}) { |m| "#{extension}/spec/requests/#{m[1]}_spec.rb" }
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT)
2
+
3
+ def setup_environment
4
+ # Configure Rails Environment
5
+ ENV["RAILS_ENV"] ||= 'test'
6
+
7
+ require File.expand_path("../../config/environment", __FILE__)
8
+
9
+ require 'rspec/rails'
10
+ require 'capybara/rspec'
11
+
12
+ Rails.backtrace_cleaner.remove_silencers!
13
+
14
+ RSpec.configure do |config|
15
+ config.mock_with :rspec
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.filter_run :focus => true
18
+ config.run_all_when_everything_filtered = true
19
+ end
20
+ end
21
+
22
+ def each_run
23
+ Rails.cache.clear
24
+ ActiveSupport::Dependencies.clear
25
+ FactoryGirl.reload
26
+
27
+ # Requires supporting files with custom matchers and macros, etc,
28
+ # in ./support/ and its subdirectories including factories.
29
+ ([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | ::Refinery::Plugins.registered.pathnames).map{|p|
30
+ Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s]
31
+ }.flatten.sort.each do |support_file|
32
+ require support_file
33
+ end
34
+ end
35
+
36
+ # If spork is available in the Gemfile it'll be used but we don't force it.
37
+ unless (begin; require 'spork'; rescue LoadError; nil end).nil?
38
+ Spork.prefork do
39
+ # Loading more in this block will cause your tests to run faster. However,
40
+ # if you change any configuration or code from libraries loaded here, you'll
41
+ # need to restart spork for it take effect.
42
+ setup_environment
43
+ end
44
+
45
+ Spork.each_run do
46
+ # This code will be run each time you run your specs.
47
+ each_run
48
+ end
49
+ else
50
+ setup_environment
51
+ each_run
52
+ end
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ class TestingGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_guardfile
6
+ template "Guardfile"
7
+ end
8
+
9
+ def copy_spec_helper
10
+ directory "spec"
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ namespace :refinery do
2
+ namespace :testing do
3
+ desc "Generates a dummy app for testing"
4
+ task :dummy_app => [:setup_dummy_app, :setup_extension, "extension:setup"]
5
+
6
+ task :setup_dummy_app do
7
+ require 'refinerycms'
8
+
9
+ params = %w(--quiet)
10
+ params << "--database=#{ENV['DB']}" if ENV['DB']
11
+
12
+ Refinery::DummyGenerator.start params
13
+
14
+ Refinery::CmsGenerator.start %w[--quiet --fresh-installation]
15
+ end
16
+
17
+ # This task is a hook to allow extensions to pass configuration
18
+ # Just define this inside your extension's Rakefile or a .rake file
19
+ # and pass arbitrary code. Example:
20
+ #
21
+ # namespace :refinery do
22
+ # namespace :testing do
23
+ # task :setup_extension do
24
+ # require 'refinerycms-my-extension'
25
+ # Refinery::MyEngineGenerator.start %w[--quiet]
26
+ # end
27
+ # end
28
+ # end
29
+ task :setup_extension do
30
+ end
31
+
32
+ desc "Remove the dummy app used for testing"
33
+ task :clean_dummy_app do
34
+ path = Refinery::Testing::Railtie.target_extension_path.join('spec', 'dummy')
35
+
36
+ path.rmtree if path.exist?
37
+ end
38
+
39
+ namespace :extension do
40
+ desc "Initialize the testing environment"
41
+ task :setup => [:init_test_database]
42
+
43
+ task :init_test_database do
44
+ task_params = [%Q{ bundle exec rake -f #{Refinery::Testing::Railtie.target_extension_path.join('Rakefile')} }]
45
+ task_params << %Q{ app:db:test:prepare }
46
+
47
+ system task_params.join(' ')
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'refinerycms-core'
2
+ require 'rspec-rails'
3
+ require 'factory_girl_rails'
4
+
5
+ module Refinery
6
+ autoload :TestingGenerator, 'generators/refinery/testing/testing_generator'
7
+
8
+ module Testing
9
+ class << self
10
+ def root
11
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
12
+ end
13
+
14
+ # Load the factories of all currently loaded extensions
15
+ def load_factories
16
+ Refinery.extensions.each do |extension_const|
17
+ if extension_const.respond_to?(:factory_paths)
18
+ extension_const.send(:factory_paths).each do |path|
19
+ FactoryGirl.definition_file_paths << path
20
+ end
21
+ end
22
+ end
23
+ FactoryGirl.find_definitions
24
+ end
25
+ end
26
+
27
+ require 'refinery/testing/railtie'
28
+ require 'refinery/testing/url_helper'
29
+
30
+ autoload :ControllerMacros, 'refinery/testing/controller_macros'
31
+ autoload :RequestMacros, 'refinery/testing/request_macros'
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Refinery
2
+ module Testing
3
+ module ControllerMacros
4
+ autoload :Authentication, 'refinery/testing/controller_macros/authentication'
5
+ autoload :Methods, 'refinery/testing/controller_macros/methods'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ module Refinery
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 login_user
10
+ before(:each) do
11
+ @user = FactoryGirl.create(:user)
12
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
13
+ sign_in @user
14
+ end
15
+ end
16
+
17
+ def login_refinery_user
18
+ before(:each) do
19
+ @refinery_user = FactoryGirl.create(:refinery_user)
20
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
21
+ sign_in @refinery_user
22
+ end
23
+ end
24
+
25
+ def login_refinery_superuser
26
+ before(:each) do
27
+ @refinery_superuser = FactoryGirl.create(:refinery_superuser)
28
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
29
+ sign_in @refinery_superuser
30
+ end
31
+ end
32
+
33
+ def login_refinery_translator
34
+ before(:each) do
35
+ @refinery_translator = FactoryGirl.create(:refinery_translator)
36
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
37
+ sign_in @refinery_translator
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,33 @@
1
+ module Refinery
2
+ module Testing
3
+ module ControllerMacros
4
+ module Methods
5
+ def get(action, parameters = nil, session = nil, flash = nil)
6
+ process_refinery_action(action, parameters, session, flash, "GET")
7
+ end
8
+
9
+ # Executes a request simulating POST HTTP method and set/volley the response
10
+ def post(action, parameters = nil, session = nil, flash = nil)
11
+ process_refinery_action(action, parameters, session, flash, "POST")
12
+ end
13
+
14
+ # Executes a request simulating PUT HTTP method and set/volley the response
15
+ def put(action, parameters = nil, session = nil, flash = nil)
16
+ process_refinery_action(action, parameters, session, flash, "PUT")
17
+ end
18
+
19
+ # Executes a request simulating DELETE HTTP method and set/volley the response
20
+ def delete(action, parameters = nil, session = nil, flash = nil)
21
+ process_refinery_action(action, parameters, session, flash, "DELETE")
22
+ end
23
+
24
+ private
25
+
26
+ def process_refinery_action(action, parameters = nil, session = nil, flash = nil, method = "GET")
27
+ parameters ||= {}
28
+ process(action, parameters.merge!(:use_route => :refinery), session, flash, method)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module Refinery
2
+ module Testing
3
+ class Railtie < Rails::Railtie
4
+ railtie_name :refinerycms_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
+ # Refinery::Testing::Railtie.load_dummy_tasks(File.dirname(__FILE__))
17
+ #
18
+ # Refinery::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 'refinery/tasks/testing.rake'
22
+ end
23
+ end
24
+
25
+ config.after_initialize do
26
+ Refinery.register_extension(Refinery::Testing)
27
+ Testing.load_factories
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module Refinery
2
+ module Testing
3
+ module RequestMacros
4
+ autoload :Authentication, 'refinery/testing/request_macros/authentication'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ module Refinery
2
+ module Testing
3
+ module RequestMacros
4
+ module Authentication
5
+ def login_refinery_user
6
+ before do
7
+ password = '123456'
8
+ refinery_user = FactoryGirl.create(:refinery_user, {
9
+ :username => "refinerycms",
10
+ :password => password,
11
+ :password_confirmation => password,
12
+ :email => "refinerycms@refinerycms.com"
13
+ })
14
+
15
+ visit refinery.new_refinery_user_session_path
16
+
17
+ fill_in "Login", :with => refinery_user.username
18
+ fill_in "Password", :with => password
19
+
20
+ click_button "Sign in"
21
+ end
22
+ end
23
+
24
+ def login_refinery_superuser
25
+ before(:each) do
26
+ password = '123456'
27
+ refinery_superuser = FactoryGirl.create(:refinery_superuser, {
28
+ :username => "refinerycms",
29
+ :password => password,
30
+ :password_confirmation => password,
31
+ :email => "refinerycms@refinerycms.com"
32
+ })
33
+
34
+ visit refinery.new_refinery_user_session_path
35
+
36
+ fill_in "Login", :with => refinery_superuser.username
37
+ fill_in "Password", :with => password
38
+
39
+ click_button "Sign in"
40
+ end
41
+ end
42
+
43
+ def login_refinery_translator
44
+ before do
45
+ password = '123456'
46
+ FactoryGirl.create(:refinery_user)
47
+ user = FactoryGirl.create(:refinery_translator, {
48
+ :password => password,
49
+ :password_confirmation => password
50
+ })
51
+
52
+ visit refinery.new_refinery_user_session_path
53
+
54
+ fill_in "Login", :with => user.username
55
+ fill_in "Password", :with => password
56
+
57
+ click_button "Sign in"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,9 @@
1
+ module Refinery
2
+ module Testing
3
+ module UrlHelper
4
+ def refinery
5
+ Refinery::Core::Engine.routes.url_helpers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,50 +1 @@
1
- require 'refinerycms-core'
2
- require 'rspec-rails'
3
-
4
- module Refinery
5
- module Testing
6
-
7
- class << self
8
- attr_accessor :root
9
- def root
10
- @root ||= Pathname.new(File.expand_path('../../', __FILE__))
11
- end
12
- end
13
-
14
- class Engine < ::Rails::Engine
15
-
16
- initializer 'serve static assets' do |app|
17
- app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
18
- end
19
-
20
- config.before_configuration do
21
- ::Refinery::Application.module_eval do
22
- def load_tasks
23
- super
24
-
25
- # To get specs from all Refinery engines, not just those in Rails.root/spec/
26
- ::RSpec::Core::RakeTask.module_eval do
27
- def pattern
28
- [@pattern] | ::Refinery::Plugins.registered.pathnames.map{|p|
29
- p.join('spec', '**', '*_spec.rb').to_s
30
- }
31
- end
32
- end if defined?(::RSpec::Core::RakeTask)
33
- end
34
- end
35
- end
36
-
37
- config.after_initialize do
38
- ::Refinery::Plugin.register do |plugin|
39
- plugin.pathname = root
40
- plugin.name = 'refinerycms_testing_plugin'
41
- plugin.version = ::Refinery.version
42
- plugin.hide_from_menu = true
43
- end
44
- end
45
- end
46
-
47
- end
48
- end
49
-
50
- ::Refinery.engines << 'testing'
1
+ require 'refinery/testing'