samvera-deprecated / curate

A data curation Ruby on Rails engine built on Hydra and Sufia
Other
17 stars 16 forks source link

Works generator generates tests that fail miserably #513

Open flyingzumwalt opened 10 years ago

flyingzumwalt commented 10 years ago

In a freshly generated Rails app where I ran the rails g curate -f generator, When I run

$ rails g curate:work Text

it adds a suite of 50+ tests. Most of those tests fail.

To get most of the generated tests to pass

I had to do the following:

In spec/spec_helper.rb, add

require 'curate/spec_support'

AND THEN add these to Gemfile:

gem 'poltergeist' 
gem 'vcr'
gem 'webmock'

AND

  1. delete spec/factories/people_factory.rb
  2. copy spec/matchers from curate into host app spec/support/matchers

That leaves 4 tests still failing

  1) Text behaves like remotely_identified by doi with valid attributes mints!
     Failure/Error: Hydra::RemoteIdentifier.mint(remote_service_name, subject)
     RuntimeError:
       Make sure to set your Curate.configuration.application_root_url
     Shared Example Group: "remotely_identified" called from ./spec/repository_models/text_spec.rb:14
     # ./config/initializers/hydra-remote_identifier_config.rb:6:in `block (4 levels) in <top (required)>'

  2) CurationConcern::TextsController behaves like is_a_curation_concern_controller #edit someone elses private work should show 401 Unauthorized
     Failure/Error: get :edit, id: a_work
     CanCan::AccessDenied:
       You are not authorized to access this page.
     Shared Example Group: "is_a_curation_concern_controller" called from ./spec/controllers/curation_concern/texts_controller_spec.rb:6
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/cancan-1.6.10/lib/cancan/ability.rb:208:in `authorize!'
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/cancan-1.6.10/lib/cancan/controller_additions.rb:338:in `authorize!'
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/bundler/gems/curate-d17e75b7e862/app/controllers/curation_concern/base_controller.rb:40:in `authorize_curation_concern!'

  3) CurationConcern::TextsController behaves like is_a_curation_concern_controller #edit someone elses public work should show me the page
     Failure/Error: get :edit, id: a_work
     CanCan::AccessDenied:
       You are not authorized to access this page.
     Shared Example Group: "is_a_curation_concern_controller" called from ./spec/controllers/curation_concern/texts_controller_spec.rb:6
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/cancan-1.6.10/lib/cancan/ability.rb:208:in `authorize!'
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/cancan-1.6.10/lib/cancan/controller_additions.rb:338:in `authorize!'
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/bundler/gems/curate-d17e75b7e862/app/controllers/curation_concern/base_controller.rb:40:in `authorize_curation_concern!'

  4) CurationConcern::TextsController behaves like is_a_curation_concern_controller #new my work should show me the page
     Failure/Error: expect(response.body).to have_tag('.promote-doi .control-group') do
     NoMethodError:
       undefined method `has_tag?' for #<String:0x007f863c423cf8>
     Shared Example Group: "is_a_curation_concern_controller" called from ./spec/controllers/curation_concern/texts_controller_spec.rb:6
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/rspec-expectations-2.14.5/lib/rspec/matchers/built_in/has.rb:10:in `matches?'
     # /Users/matt/.rvm/gems/ruby-1.9.3-p545/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'

Finished in 34.37 seconds
52 examples, 4 failures
jeremyf commented 10 years ago

Failing test 4) add "gem 'rspec-html-matchers'" in Gemfile

flyingzumwalt commented 10 years ago

That did fix the 4th failing test.

jeremyf commented 10 years ago

Failing test 1) add to your environment file https://github.com/ndlib/curate_vanilla/blob/master/config/environments/staging.rb#L45

jeremyf commented 10 years ago

For test 2 & 3) Try running LOCAL=TRUE rspec ./spec/controllers/curation_concern/texts_controller_spec.rb:6

The LOCAL means "Raise the exceptions instead of using the exception handler." There may be something buried in there.

flyingzumwalt commented 10 years ago

Same errors with LOCAL=TRUE rspec ./spec/controllers/curation_concern/texts_controller_spec.rb

jeremyf commented 10 years ago

@flyingzumwalt Actually, I believe it is working. However your application is treating exceptions as local. That was one thing I had setup for Curate's tests to assume that exceptions are not local.

So the proposed solution would be to handle either case.

flyingzumwalt commented 10 years ago

Ah. Ok. I'll do that in my app, but this ticket will be important to address in Curate so that future adopters won't run into it.

jeremyf commented 10 years ago

Absolutely. And shouldn't be closed.

I believe your two steps are appropriate and should have the test case: "And the generated model tests work"

jeremyf commented 10 years ago

As an interesting aside - curate is assuming the use of rspec. Even in the spec_support.

scherztc commented 10 years ago

Would it be useful to have something similar to sufia_models with curation_concerns (works)?