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

Restoring anonymous resource declaration in specs #4493

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Sep 2, 2020

At issue is "human_readable_type" leverages the resource's model name,
which, by default, uses ActiveModel::Name. By adding .model_name that
returns an instance of ActiveModel::Name, the tests now pass.

I could imagine adding a spec helper method for generating an anonymous
resource. This method would encapsulate the behavior. If we were to go
this route, we'd want to update all of our existing Class.new declarations.

module Hyrax::SpecSupport
  def self.build_anonymous_resource_class(klass, name: "Anonymous", &block)
     Class.new(klass) do
       def self.model_name
         ActiveModel::Name.new(self, nil, name)
       end
       instance_exec(&block)
     end
  end
end

Hyrax::SpecSupport.build_anonymous_resource_class(Hyrax::Work, name: "Anonymouse") do
  include Hyrax::Schema(:basic_metadata)
end

@samvera/hyrax-code-reviewers

At issue is "human_readable_type" leverages the resource's model name,
which, by default, uses ActiveModel::Name.  By adding `.model_name` that
returns an instance of ActiveModel::Name, the tests now pass.

I could imagine adding a spec helper method for generating an anonymous
resource.  This method would encapsulate the behavior.  If we were to go
this route, we'd want to update all of our existing `Class.new` declarations.

```ruby
module Hyrax::SpecSupport
  def self.build_anonymous_resource_class(klass, name: "Anonymous", &block)
     Class.new(klass) do
       def self.model_name
         ActiveModel::Name.new(self, nil, name)
       end
       instance_exec(&block)
     end
  end
end

Hyrax::SpecSupport.build_anonymous_resource_class(Hyrax::Work, name: "Anonymouse") do
  include Hyrax::Schema(:basic_metadata)
end
```
Comment on lines +22 to +24
def self.model_name
ActiveModel::Name.new(self, nil, "TemporaryResource")
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@no-reply Lines 22-24 represent the change from master to address the ArgumentError. Does this change fit with your expectation for code resiliency?

Copy link
Member

@no-reply no-reply left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good.

@no-reply no-reply merged commit 54137b5 into valkyrie_indexer/human_readable_type Sep 2, 2020
@no-reply no-reply deleted the amending-human-readable-type-spec-change branch September 2, 2020 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants