diff --git a/.gitignore b/.gitignore index 39fb2e0..ab9b488 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .bundle/ log/*.log pkg/ -spec/dummy +spec/internal Gemfile.lock gemfiles/*.lock diff --git a/Gemfile b/Gemfile index 53b2bfc..0c14983 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index a032fa8..cd32e80 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/gemfiles/edge-hydra-head.gemfile b/gemfiles/edge-hydra-head.gemfile index ed47656..b0f3534 100644 --- a/gemfiles/edge-hydra-head.gemfile +++ b/gemfiles/edge-hydra-head.gemfile @@ -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' diff --git a/gemfiles/gemfile.rails4 b/gemfiles/gemfile.rails4 index f0b18db..7b43b28 100644 --- a/gemfiles/gemfile.rails4 +++ b/gemfiles/gemfile.rails4 @@ -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' diff --git a/hydra-editor.gemspec b/hydra-editor.gemspec index d657e5e..5a9ecba 100644 --- a/hydra-editor.gemspec +++ b/hydra-editor.gemspec @@ -19,6 +19,7 @@ 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" @@ -26,4 +27,5 @@ Gem::Specification.new do |s| s.add_development_dependency "capybara" s.add_development_dependency "devise" s.add_development_dependency "hydra-head" + s.add_development_dependency "engine_cart" end diff --git a/lib/hydra-editor.rb b/lib/hydra-editor.rb index 62eb4ed..a99949b 100644 --- a/lib/hydra-editor.rb +++ b/lib/hydra-editor.rb @@ -1,4 +1,3 @@ -require "cancan" require "hydra_editor/engine" require "bootstrap_forms" diff --git a/lib/hydra_editor/engine.rb b/lib/hydra_editor/engine.rb index 09dc7f1..a26cc81 100644 --- a/lib/hydra_editor/engine.rb +++ b/lib/hydra_editor/engine.rb @@ -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 diff --git a/spec/features/record_editing_spec.rb b/spec/features/record_editing_spec.rb index d7adb96..007268d 100644 --- a/spec/features/record_editing_spec.rb +++ b/spec/features/record_editing_spec.rb @@ -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") diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb deleted file mode 100644 index 54125cd..0000000 --- a/spec/models/bookmark_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' - -describe Bookmark do - it "should be success" do - true.should be_true - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3af8ef..a78e7a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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! @@ -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 diff --git a/spec/support/lib/generators/test_app_generator.rb b/spec/test_app_templates/lib/generators/test_app_generator.rb similarity index 55% rename from spec/support/lib/generators/test_app_generator.rb rename to spec/test_app_templates/lib/generators/test_app_generator.rb index e3ac6bb..a2fdcd7 100644 --- a/spec/support/lib/generators/test_app_generator.rb +++ b/spec/test_app_templates/lib/generators/test_app_generator.rb @@ -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"