Skip to content

Conversation

@davetheninja
Copy link

Ran into trouble using repositories on 2.0.0. Confirmed same on 1.9.3 and noted it was working on 2.1.0.

You will see that the fix is very straight forward and I have a feeling it is a bug in 2.1.0 that is allowing the use of include within a class level of execution.

Tried to track down some evidence of the 2.1.0 bug theory, best i could find that explains the expected behaviours: http://stackoverflow.com/a/7296037

Original Exception:

% rake test
/Users/davetheninja/Work/oss/chassis-ah/lib/chassis/strategy.rb:83:in `included': private method `include' called for Chassis::Repo:Class (NoMethodError)
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis/repo.rb:27:in `include'
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis/repo.rb:27:in `<class:Repo>'
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis/repo.rb:20:in `<module:Chassis>'
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis/repo.rb:3:in `<top (required)>'
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis.rb:63:in `require_relative'
    from /Users/davetheninja/Work/oss/chassis-ah/lib/chassis.rb:63:in `<top (required)>'
    from /Users/davetheninja/Work/oss/chassis-ah/test/test_helper.rb:4:in `require'
    from /Users/davetheninja/Work/oss/chassis-ah/test/test_helper.rb:4:in `<top (required)>'
    from /Users/davetheninja/Work/oss/chassis-ah/test/chassis_test.rb:1:in `require_relative'
    from /Users/davetheninja/Work/oss/chassis-ah/test/chassis_test.rb:1:in `<top (required)>'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib" -I"/Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib" "/Users/davetheninja/.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems/rake-10.1.1/lib/rake/rake_test_loader.rb" "test/**/*_test.rb" ]

Tasks: TOP => test
(See full trace by running task with --trace)

@davetheninja
Copy link
Author

Having overcome this initial issue, I am running into more problems when running in 1.9.x (assuming 2.0.0 also).

I need to run the app I am building on JRuby so need to sort backwards compatibility throughout Chassis.

Hold off on this PR for now. I want to do some extensive testing first and sort out the compatibility on my own fork. I will re-issue another PR when it is all working nicely.

I will create a set of examples using each of the components within tests (real life usages/integration of the components) and re-run over 1.9.x, 2.0.x and 2.1.x to ensure its all working.

Cheers

@davetheninja
Copy link
Author

Just gone through repo + custom adapter + persistence + initializable....

All good on 1.9.x, 2.0.x and 2.1.x with this PR.

Turns the issues I had relating to the previous comment were a type-o on my part.

Please review the PR and let me know if you have any concerns.

Trivial code used to test below, will wire it up into my app at work tomorrow to try again.

class RepositoryExamples < MiniTest::Unit::TestCase

  class MyAdapter < Chassis::MemoryRepo
    def query_find_by_id(klass, q)
      [My.new(id: q.id)]
    end
  end

  class MyRepo
    extend Chassis::Repo::Delegation
    class << self
      def find_by_id(id)
        query FindById.new id
      end
    end
  end

  FindById = Struct.new :id

  class My
    include Chassis::Persistence
    include Chassis::Initializable
  end

  def test_can_use_custom_adapter_with_queries
    MyRepo.backend.register :test, MyAdapter.new
    MyRepo.backend.use :test
    actual = MyRepo.find_by_id 1
    expected = [My.new(id: 1)]
    assert_equal expected, actual
  end

@inem
Copy link
Contributor

inem commented Apr 16, 2014

Same for me on 2.0.0 : https://gist.github.com/inem/10804730

example is from future blog post: ahawkins/hawkins.io@ce6f82d?short_path=c6c8a6a#diff-c6c8a6aebf2010ef8b6a3f3b33c61813

passed this line on 2.1.0, but next I got this: https://gist.github.com/inem/10814522#file-app-rb-L35

inem referenced this pull request in ahawkins/hawkins.io Apr 16, 2014
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.

2 participants