Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to rspec_3 and use engine_cart for testing #34

Merged
merged 1 commit into from
Jun 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.bundle/
log/*.log
pkg/
spec/dummy
spec/internal
Gemfile.lock
gemfiles/*.lock
17 changes: 8 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
source "http://rubygems.org"
source "https://rubygems.org"

# Declare your gem's dependencies in hydra-editor.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'debugger'
#

file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
if File.exists?(file)
puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
instance_eval File.read(file)
end
24 changes: 2 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,10 @@ end

Bundler::GemHelper.install_tasks

dummy = File.expand_path('../spec/dummy', __FILE__)
rakefile = File.join(dummy, 'Rakefile')

desc "Remove the dummy app"
task :clean do
sh "rm -rf #{dummy}"
end

desc "Generate the dummy app"
task :setup do
unless File.exists?("#{dummy}/Rakefile")
`rails new #{dummy}`
`cp -r spec/support/lib/generators #{dummy}/lib`
Dir.chdir(dummy) do
puts "Generating test app ..."
sh "rails generate test_app"
sh "touch public/test.html" # for spec/features/record_editing_spec.rb
end
end
end

require 'engine_cart/rake_task'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec => :setup) do |t|
RSpec::Core::RakeTask.new(:spec => 'engine_cart:generate') do |t|
t.pattern = 'spec/**/*_spec.rb'
end

Expand Down
1 change: 1 addition & 0 deletions gemfiles/edge-hydra-head.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source "https://rubygems.org"
gemspec :path=>"../"

gem 'rails', '~> 4.0.0'
gem 'sass-rails', '~> 4.0.3'

gem 'active-fedora', github: 'projecthydra/active_fedora'
gem 'hydra-head', github: 'projecthydra/hydra-head'
Expand Down
1 change: 1 addition & 0 deletions gemfiles/gemfile.rails4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source "https://rubygems.org"
gemspec path: "../"

gem 'rails', '~> 4.0.0'
gem 'sass-rails', '~> 4.0.3'

gem 'hydra', '7.0.0'

Expand Down
2 changes: 2 additions & 0 deletions hydra-editor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ Gem::Specification.new do |s|
s.add_dependency "bootstrap_forms"
s.add_dependency "active-fedora", ">= 6.3.0"
s.add_dependency "deprecation"
s.add_dependency "cancancan"

s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"
s.add_development_dependency "factory_girl_rails"
s.add_development_dependency "capybara"
s.add_development_dependency "devise"
s.add_development_dependency "hydra-head"
s.add_development_dependency "engine_cart"
end
1 change: 0 additions & 1 deletion lib/hydra-editor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "cancan"
require "hydra_editor/engine"
require "bootstrap_forms"

Expand Down
3 changes: 3 additions & 0 deletions lib/hydra_editor/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ class Engine < ::Rails::Engine
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
initializer "hydra-editor.initialize" do
require "cancan"
end
end
end
8 changes: 4 additions & 4 deletions spec/features/record_editing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
@ability.stub(:authorize!).and_return(true)
Ability.stub(:new).with(@user).and_return(@ability)
# Avoid the catalog so we don't have to run Solr
RecordsController.any_instance.stub(:redirect_after_update).and_return("/test.html")
Audio.any_instance.stub(:persisted?).and_return(true)
Audio.any_instance.stub(:new_record?).and_return(false)
Audio.any_instance.stub(:save).and_return(true)
allow_any_instance_of(RecordsController).to receive(:redirect_after_update).and_return("/404.html")
allow_any_instance_of(Audio).to receive(:persisted?).and_return(true)
allow_any_instance_of(Audio).to receive(:new_record?).and_return(false)
allow_any_instance_of(Audio).to receive(:save).and_return(true)
@record = Audio.new(pid: "foo:1", title: "Cool Track")
# We need a clone to give to the edit view b/c it gets changed by initialize_fields
@record_clone = Audio.new(pid: "foo:1", title: "Cool Track")
Expand Down
7 changes: 0 additions & 7 deletions spec/models/bookmark_spec.rb

This file was deleted.

8 changes: 6 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require 'devise'

require 'engine_cart'
EngineCart.load_application!

require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl_rails'

Rails.backtrace_cleaner.remove_silencers!
Expand All @@ -18,4 +21,5 @@
config.before(:each, :type=>"controller") { @routes = HydraEditor::Engine.routes }

config.include Warden::Test::Helpers
config.infer_spec_type_from_file_location!
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@

class TestAppGenerator < Rails::Generators::Base

def configure

def add_gems
gem 'blacklight'
gem 'hydra-head'
gem 'hydra-editor', path: '../../'
gem "factory_girl_rails"
gem 'capybara'
Bundler.with_clean_env do
run "bundle install"
end
end

def run_blacklight_generator
say_status("warning", "GENERATING BL", :yellow)
generate "blacklight:install --devise"
gsub_file "app/controllers/application_controller.rb", "layout 'blacklight'", "layout 'application'"
end

def run_hydra_generator
say_status("warning", "GENERATING Hydra", :yellow)
generate "hydra:head -f"
end

def run_migrations
rake "db:migrate"
rake "db:test:prepare"

gsub_file "app/controllers/application_controller.rb", "layout 'blacklight'", "layout 'application'"
end

def add_route
insert_into_file "config/routes.rb", :after => '.draw do' do
"\n mount HydraEditor::Engine => \"/\"\n"
end
remove_file "spec/factories/users.rb" # generated by devise
remove_file "spec/models/user_spec.rb" # generated by devise
end

# def remove_devise_cruft
# remove_file "spec/factories/users.rb" # generated by devise
# remove_file "spec/models/user_spec.rb" # generated by devise
# end

def add_create_ability
# Required for hydra-head 7+
insert_into_file "app/models/ability.rb", :after => 'custom_permissions' do
"\n can :create, :all if user_groups.include? 'registered'\n"
Expand Down