Permalink
Browse files

Split off legacy specs that depend on Horowhenua

* Split specs into those that function in the normal rails way and those
  that are hard-coded to the sample Horowhenua dataset
* Stop referencing ActiveRecord models in initializers as it breaks
  `rake db:schema:load`
* Stop loading factory_girl in development as baskets factory references
  `Basket` class constant which is not available when doing `rake db:schema:load`
  • Loading branch information...
eoinkelly committed May 18, 2015
1 parent df152df commit 932aa7cc03e915d71c7944e0a9b0ada890478775
Showing with 179 additions and 111 deletions.
  1. +23 −8 Gemfile
  2. +2 −2 Gemfile.lock
  3. +8 −11 config/{database.example → database.example.yml}
  4. +41 −25 config/environments/horowhenua.rb
  5. +2 −2 config/initializers/search_sources_configuration.rb
  6. +11 −0 horowhenua_spec/README.md
  7. 0 {spec → horowhenua_spec}/horowhenau/features/anonymous_user_spec.rb
  8. 0 {spec → horowhenua_spec}/horowhenau/features/audio_upload_spec.rb
  9. +0 −2 {spec → horowhenua_spec}/horowhenau/features/commenting_spec.rb
  10. 0 {spec → horowhenua_spec}/horowhenau/features/contributed_by_searching_spec.rb
  11. 0 {spec → horowhenua_spec}/horowhenau/features/document_upload_spec.rb
  12. 0 {spec → horowhenua_spec}/horowhenau/features/history_spec.rb
  13. 0 {spec → horowhenua_spec}/horowhenau/features/image_upload_spec.rb
  14. 0 {spec → horowhenua_spec}/horowhenau/features/membership_management_spec.rb
  15. 0 {spec → horowhenua_spec}/horowhenau/features/page_footer_links_spec.rb
  16. 0 {spec → horowhenua_spec}/horowhenau/features/page_header_links_spec.rb
  17. 0 {spec → horowhenua_spec}/horowhenau/features/related_items_spec.rb
  18. 0 {spec → horowhenua_spec}/horowhenau/features/rss_feeds_spec.rb
  19. 0 {spec → horowhenua_spec}/horowhenau/features/search_results_spec.rb
  20. 0 {spec → horowhenua_spec}/horowhenau/features/tags_spec.rb
  21. 0 {spec → horowhenua_spec}/horowhenau/features/user_login_spec.rb
  22. 0 {spec → horowhenua_spec}/horowhenau/features/user_signup_spec.rb
  23. 0 {spec → horowhenua_spec}/horowhenau/features/video_upload_spec.rb
  24. 0 {spec → horowhenua_spec}/horowhenau/features/web_link_upload_spec.rb
  25. +67 −0 horowhenua_spec/spec_helper.rb
  26. 0 {spec → horowhenua_spec}/support/horowhenua_helpers.rb
  27. 0 spec/factories/.gitkeep
  28. +0 −1 spec/horowhenau/README.md
  29. +3 −2 spec/models/topic_spec.rb
  30. +22 −58 spec/spec_helper.rb
31 Gemfile
@@ -188,8 +188,6 @@ gem 'validates_xml', '1.0.3' # >> 2007-06-06
# our own fork to be sure that the repo will not be deleted in future.
gem 'authorization', github: 'kete/rails-authorization-plugin'



# ######
# Assets
# ######
@@ -212,15 +210,9 @@ group :development do
gem 'capistrano-rbenv', '~> 2.0.2'
gem 'capistrano-rails', '~> 1.1.2'
gem 'capistrano-bundler', '~> 1.1.3'

end

group :development, :test do
gem 'poltergeist'
gem "rspec-rails", "~> 3.0.0"
gem "factory_girl_rails", "~> 4.3.0"
gem "capybara", "~> 2.4.1"
gem "database_cleaner"
gem "pry-rails"
gem "debugger", :platforms => [:mingw_19, :ruby_19]
gem 'debugger-xml', :platforms => [:mingw_19, :ruby_19]
@@ -229,3 +221,26 @@ group :development, :test do
gem 'awesome_print'
end

group :test do
gem 'poltergeist'
gem "rspec-rails", "~> 3.0.0"

# Why we cannot load factories by default in :development
#
# Some of our factories reference models in a way that cannot be made lazy.
# This causes `rake environment` to depend on a working set of ActiveRecord
# models. While this dependency is not a problem in most cases, it does cause
# `rake db:schema:load` to fail (because `rake db:schema:load` task depends
# on `rake environment` and obviously we don't have a working set of models
# during schema load).
#
# If you need factories in `rails console` in development then you can do
#
# irb> require 'factory_girl'
# irb> FactoryGirl.find_definitions
#
gem "factory_girl_rails", "~> 4.3.0"

gem "capybara", "~> 2.4.1"
gem "database_cleaner", "~> 1.4.1"
end
@@ -136,7 +136,7 @@ GEM
compass-rails (1.0.3)
compass (>= 0.12.2, < 0.14)
curb (0.8.5)
database_cleaner (1.2.0)
database_cleaner (1.4.1)
debugger (1.6.2)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
@@ -354,7 +354,7 @@ DEPENDENCIES
chronic
coffee-rails (~> 3.2.1)
compass-rails
database_cleaner
database_cleaner (~> 1.4.1)
debugger
debugger-xml
dynamic_form (~> 1.1.4)
@@ -1,23 +1,20 @@

development: &dev
adapter: postgresql
database: kete_development
username: root
password:
host: localhost
encoding: utf8

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
test:
<<: *dev
database: kete_test

production: &production
adapter: postgresql
encoding: unicode
database: kete_production
pool: 5
username: root
password:
horowhenua:
<<: *dev
database: kete_horowhenua

horowhenua:
<<: *dev
database: kete_production
@@ -1,28 +1,44 @@
KeteApp::Application.configure do # Settings specified here will take precedence over those in config/environment.rb
KeteApp::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
#
## In the development environment your application's code is reloaded on
## every request. This slows down response time but is perfect for development
## since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
#
## Log error messages when you accidentally call methods on nil.
#config.whiny_nils = true
#
## Show full error reports and disable caching
#config.action_controller.consider_all_requests_local = true
#config.action_view.debug_rjs = true
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = false # RABID: there are still lots of errors in the full rails env so turn this off so we can run specs on a few models without crashing

# Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Log error messages when you accidentally call methods on nil
config.whiny_nils = true

# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.active_support.deprecation = :log

## Don't care if the mailer can't send
#config.action_mailer.raise_delivery_errors = false
#config.action_mailer.smtp_settings = {
# :address => "localhost",
# :port => 25,
# :domain => 'localhost.localdomain',
# :enable_starttls_auto => false
#}

# Attachments (images/audio) link on horowhenua, because our DB is taken from this
config.attachments_overide_url = "http://horowhenua.kete.net.nz"

# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Raise exception on mass assignment protection for Active Record models
# config.active_record.mass_assignment_sanitizer = :strict

# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr

# ActionMailer Config
config.action_mailer.default_url_options = { :host => 'kete.org.nz' }

# Attachments (images/audio) link files on the local disk.
# config.attachments_overide_url = nil
config.attachments_overide_url = 'http://horowhenua.kete.net.nz'
end
@@ -1,6 +1,6 @@
ExternalSearchSources[:authorized_role] = "site_admin"
ExternalSearchSources[:unauthorized_path] = "/#{Basket.site_basket.urlified_name}"
ExternalSearchSources[:default_url_options] = { :urlified_name => Basket.site_basket.urlified_name }
ExternalSearchSources[:unauthorized_path] = "/#{SystemSetting.default_basket}"
ExternalSearchSources[:default_url_options] = { :urlified_name => SystemSetting.default_basket }
ExternalSearchSources[:default_link_classes] = 'generic-result-wrapper skip_div_click'
ExternalSearchSources[:image_link_classes] = 'image-result-wrapper skip_div_click'
ExternalSearchSources[:cache_results] = true
@@ -0,0 +1,11 @@
# Horowhenua specs (You can probably ignore these)

These legacy specs depend on a canonical fixture dataset from Horowhenua. They
were used as a stop-gap during the rails 2->3 upgrade process.

The sample data is only available to Rabid Technologies so these specs are not generally useful.

To run these specs:

1. Ensure you have sample data loaded into `kete_horowhenua`
1. `bundle exec rspec --default-path=./horowhenua_spec`
@@ -3,5 +3,3 @@
feature "Comments (discussions)" do
# Adding comments or browsing them from search has been removed.
end


@@ -0,0 +1,67 @@
# To run these specs:
#
# # ensure you have sample data loaded into kete_horowhenua
# $ bundle exec rspec --default-path=./horowhenua_spec
#
puts "******************************************************"
puts "RUNNING HOROWHENUA DATA SPECS"
puts ""
puts "* These specs depend on a `kete_horowhenua` database that contains a canonical"
puts " set of sample data."
puts ""
puts "******************************************************"

ENV["RAILS_ENV"] ||= 'horowhenua'
puts "Current rails enviornment is: #{ENV['RAILS_ENV']}"

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'database_cleaner'

# manually load factory_girl
require 'factory_girl'
FactoryGirl.find_definitions

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

Dir[Rails.root.join("horowhenua_spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end

# Capybara runs Javascript enabled specs run in a separate process which gets a
# separate DB connection by default. Using multiple connections is quicker and
# is easy to manage provided that your test database can be emptied between
# runs. We are in an unusual situation where we have a test DB with a lot of
# data so we resort to this old-school hack from:
# http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/

class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil

def self.connection
@@shared_connection || retrieve_connection
end
end

# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
No changes.

This file was deleted.

Oops, something went wrong.
@@ -7,9 +7,10 @@

it "allows setting of a custom title" do
unique = "a unique title"
topic = Topic.new(title: unique, topic_type: TopicType.last, basket: Basket.last)
topic_type = FactoryGirl.create(:topic_type)
basket = FactoryGirl.create(:basket)
topic = Topic.new(title: unique, topic_type: topic_type, basket: basket)
topic.save!
expect(topic.title).to eq(unique)
end

end
@@ -1,86 +1,50 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rails'
require 'database_cleaner'

require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# we use database_cleaner to manage cleaning so tell ActiveRecord not to wrap
# things in transactions
config.use_transactional_fixtures = false

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end

# config.before(:suite) do
# DatabaseCleaner.strategy = :transaction
# end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end

config.before(:each) do
DatabaseCleaner.start
end

# JS enabled specs happen in a separate process (with a separate DB
# connection) to the app. We turn off cleaning for them because the changes
# they make were not made in our transaciton so rolling back has no effect.
# Basically they have to clean up after themselves.
# config.before(:each, :js => true) do
# DatabaseCleaner.strategy = nil
# end
#
# config.before(:each) do
# puts "starting databascleaner"
# DatabaseCleaner.start
# end
#
# config.after(:each) do
# puts "running databaseclean.clean"
# DatabaseCleaner.clean
# end
config.after(:each) do
DatabaseCleaner.clean
end

# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
config.infer_base_class_for_anonymous_controllers = true

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
end



# Capybara runs Javascript enabled specs run in a separate process which gets a
# separate DB connection by default. Using multiple connections is quicker and
# is easy to manage provided that your test database can be emptied between
# runs. We are in an unusual situation where we have a test DB with a lot of
# data so we resort to this old-school hack from:
# http://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/

class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil

def self.connection
@@shared_connection || retrieve_connection
end
end

# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

0 comments on commit 932aa7c

Please sign in to comment.