Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Cannot define multiple 'included' blocks for a Concern #111

Open
safetypins opened this issue Mar 9, 2015 · 7 comments
Open

Cannot define multiple 'included' blocks for a Concern #111

safetypins opened this issue Mar 9, 2015 · 7 comments

Comments

@safetypins
Copy link

I'm attempting to use vestal_versions with a Rails 4.2 app, and Ruby 2.2, But after adding the gem, running the migration, and adding the 'versioned' method to the models I want to be versioned, I get the following error. Is there a rails 4/ruby 2.2 compatible fork of vestal_versions out there?

Extracted source (around line #126):
124 def included(base = nil, &block)
125 if base.nil?
126 raise MultipleIncludedBlocks if instance_variable_defined?(:@_included_block)
127 128 @_included_block = block 129 else`

vendor/bundle/ruby/2.1.0/gems/activesupport-4.2.0/lib/active_support/concern.rb:126:in 'included'
vendor/bundle/ruby/2.1.0/bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/version_tagging.rb:29:in '<module:VersionMethods>'
vendor/bundle/ruby/2.1.0/bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/version_tagging.rb:26:in '<module:VestalVersions>'

@R1V3R5
Copy link

R1V3R5 commented Mar 25, 2015

I just got the same error with my app. Also Rails 4.2.0 and Ruby 2.2.0.

ActiveSupport::Concern::MultipleIncludedBlocks - Cannot define multiple 'included' blocks for a Concern:
activesupport (4.2.0) lib/active_support/concern.rb:126:in included' bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/version_tagging.rb:29:inmodule:VersionMethods'
bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/version_tagging.rb:26:in <module:VestalVersions>' bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/version_tagging.rb:1:in<top (required)>'
bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions.rb:116:in versioned' bundler/gems/vestal_versions-beccc5744ec0/lib/vestal_versions/versioned.rb:10:inversioned'

@safetypins
Copy link
Author

Try my fork: https://github.com/safetypins/vestal_versions

I resolved all of the errors I ran into and it appears to be working as expected. The only thing that doesn't work as advertised originally is the user attribution. It looks like it's just not possible to associate the user passing the updated_by attribute to update_attributes(). However, I was able to set the updated_by property prior to the update_attributes() call and it attributed changes as expected. This was suggested somewhere else on the internets, and I just added the instructions to the README so it was clear.

I haven't tested everything. Frankly I'm uncertain of how to test a module, I'm not familiar with rspec, I'm very busy with other things, and it's working for me, so I'm not very motivated to figure it out. I also don't have time to figure out how to turn this thing into a proper gem that can be installed via gem install, but I think the gem is worth it. It seems like a really good implementation of versioning.

I think the only thing I don't like is the duplication of content: each revision contains the previous and new values. If you're versioning a long text field, this could get really bulky over time. I don't understand why the values need to be stored from and two, especially since the model tracks a self-referential "reverted_from" column. Maybe to reduce database interaction?

Anyway, I was originally thinking it would be nice to integrate the functionality of differ or diffy but it would probably be better to just use both gems to implement the revision UI the way I want..

@R1V3R5
Copy link

R1V3R5 commented Mar 26, 2015

AWESOME! I totally get what you're saying about being too busy with important stuff to be able to test/fully get the gem in working condition, i'm too busy as well...as far as I'm concerned though it's working now and I really appreciate it. If I run into any issues or whatnot I'll try and figure it out. How are you setting the updated_by prior to update_attributes?

@safetypins
Copy link
Author

Here's my code:

https://gist.github.com/safetypins/e719c3ebc2b0a3de317e

The attr_accessor property of updated_by is set in the vestal_versions module (I think), so I'm pretty sure all you have to do is assign a value (you can use a name or an instance) and then update_attributes. Keep in mind, if no attributes are changed, then there won't be a new version created.

@R1V3R5
Copy link

R1V3R5 commented Mar 26, 2015

Don't know if you've ran into this problem or if it's just on my app but I cannot delete models that are versioned.
NoMethodError - undefined method `delete_version?'

@safetypins
Copy link
Author

I haven't. The models that I'm versioning in the app are not designed to be deleted, so I haven't tried to delete any of them.

So, there's this thing that they got rid of in modules, can't remember exactly, but if you look through the commits, you'll see that I performed the same operation in several of the files. It's basically a block that they removed, something about instance methods, I think? in several places I was getting an undefined method error, and when I looked, I saw the the function was defined, but it was inside this block, and if I moved it outside the block, then it worked correctly. I don't fully understand it.

@keithpitty
Copy link

@R1V3R5 I can confirm that I'm getting the same error when I try to destroy an instance. We are now looking into migrating away from vestal_versions to paper_trail.

davinlagerroos pushed a commit to SeniorServiceAmerica/vestal_versions that referenced this issue Apr 12, 2020
See laserlemon#111. This issue
seems to be the gem defines 2 Version::VersionMethods modules, one users.rb
and one in version_tagging.rb, each with an `included` block.

As quick proof of concept rename the module in VersionTagging (since we
don't use that feature) to `VersionTaggingMethods` and update the
`class_eval` block to reflect the change.

A better approach might be to namesoace each `VersionMethods` module to
the parent module, e.g. `VestalVersions::VersionTagging::VersionMethods`
and `VestalVersions::User::VersionMethods`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants