Code Monkey home page Code Monkey logo

Comments (10)

gonzalo-bulnes avatar gonzalo-bulnes commented on May 26, 2024

Hi @nicolo,

This is something I should have documented long before. (You ran the test suite before without issues, right?)

Solution

# to remove all the dummy app files that are not essential (i.e. under version control)
# remove the entire dummy app
rm -rf spec/dummy
# restore the minimal dummy app
git checkout spec/dummy

# Note: the minimal dummy app should not be modified, that's why `spec/dummy` is ignored.

Explanation

The test suite re-generates the dummy app on each scenario. The dummy app which is part of the repo is the minimal dummy app, and it is required to start running the Cucumber scenarii.

What appends is that after re-generating the dummy app a few times, some new files are generated (including those from the Devise installation) which make sense in their respective scenarii, but prevent the test suite to start once their context has been dropped. The solution consists in dropping them by leveraging the Git capabilities.

from simple_token_authentication.

nicolo avatar nicolo commented on May 26, 2024

@gonzalo-bulnes Thanks for the reply. This got me a little further.

The test suite now starts running, but now I'm seeing this failure.

And User acts_as_token_authenticatable # features/step_definitions/dummy_app_steps.rb:246
expected app/models/user.rb to be present (RuntimeError)
features/any_controller_which_acts_as_token_authentication_handler_requires_authentication_from_the_correspoding_model.feature:17:in And Useracts_as_token_authenticatable`'

from simple_token_authentication.

gonzalo-bulnes avatar gonzalo-bulnes commented on May 26, 2024

At this point I need to know if you've modified the scenario which is failing. If you did, note that the step which is failing depends on the spec/dummy/app/models/user.rb file to exist (source). In the original scenario, that file, i.e theUser model, is created by the step which installs Devise (source).

If you were using another model, say Admin, you should keep both steps coherent:

Given I have a dummy app with a Devise-enabled Admin
# ...
And Admin `acts_as_token_authenticatable`

Do these observations help you?

from simple_token_authentication.

nicolo avatar nicolo commented on May 26, 2024

I have not modified anything as of yet. I'm trying to get the test suite to pass before touching the code.

from simple_token_authentication.

nicolo avatar nicolo commented on May 26, 2024

@gonzalo-bulnes am I missing any other setup steps to get this to work? I haven't changed any code yet. Could it be an issue with using Ruby 2.1.2?

from simple_token_authentication.

gonzalo-bulnes avatar gonzalo-bulnes commented on May 26, 2024

Hi @nicolo!

Could #72 have any relation with the issue?

I really don't think the Ruby version to be involved in this, I see no reason for that. (And I just ran the v1.5.0 test suite with Ruby 2.1.2 to be sure.) The protocol you described seems perfectly fine to me:

# clone the repository in a temporary directory
mkdir tmp && cd tmp
git clone [email protected]:gonzalo-bulnes/simple_token_authentication.git

# use a clean gemset
cd simple_token_authentication
rvm use --create 2.1.2@tmp_simple_token_authentication
bundle install

# run the test suite
rake

from simple_token_authentication.

nicolo avatar nicolo commented on May 26, 2024

Implementing the fix in #72 seemed to help. Down to failures from 19, but I'm now getting the error:

PrivatePosts GET /private_posts since User and Admin act as token authenticatable and PrivatePostsController acts_as_token_authentication_handler_for both when User credentials are provided token authentication is performed for that User
Failure/Error: lambda do
expected RuntimeError with "sign_in was called with resource or scope User.", got #<RuntimeError: authenticate_admin! was called.> with backtrace:
# ./app/controllers/application_controller.rb:23:in authenticate_admin!' # /Users/nicolo/projects/simple_token_authentication/lib/simple_token_authentication/acts_as_token_authentication_handler.rb:21:incall'
# /Users/nicolo/projects/simple_token_authentication/lib/simple_token_authentication/acts_as_token_authentication_handler.rb:21:in authenticate_entity!' # /Users/nicolo/projects/simple_token_authentication/lib/simple_token_authentication/acts_as_token_authentication_handler.rb:126:inauthenticate_admin_from_token!'
# ./spec/requests/private_posts_spec.rb:47:in block (7 levels) in <top (required)>' # ./spec/requests/private_posts_spec.rb:46:inblock (6 levels) in <top (required)>'
# ./spec/requests/private_posts_spec.rb:46:in `block (6 levels) in <top (required)>'

Do the tests not run in OSX? Should I try using my linux machine?

from simple_token_authentication.

gonzalo-bulnes avatar gonzalo-bulnes commented on May 26, 2024

Hi @nicolo! Of course you can use another machine, but I wish we could fix the MacOS X issues... What do you think?

... OK, I think I know where that error comes from:

expected RuntimeError with "sign_in was called with resource or scope User.", got #

The failing scenario uses a variant of the step that was fixed by #72. It also uses sed and the same fix is missing here.

I'm sorry for the duplication there, I had doubts about that, but considering that the Cucumber steps mecanism would be unfamiliar to most users, I finally decided to favor readability over cleanliness.

from simple_token_authentication.

nicolo avatar nicolo commented on May 26, 2024

Sorry for the slow response. Those fixes got the tests to work. Thanks!

from simple_token_authentication.

gonzalo-bulnes avatar gonzalo-bulnes commented on May 26, 2024

Yay! Very good news! Thanks for the feedback! :D

from simple_token_authentication.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.