Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6031473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:11:21+00:00 2026-05-23T05:11:21+00:00

Note: I am very new to Cucumber. I am trying to make a generalized

  • 0

Note: I am very new to Cucumber.

I am trying to make a generalized step (not sure if one already exists somewhere or not) so that you can easily add objects to another object, given the association exists. I want to do something like:

manage_notes.feature

Background: Login User
  Given the following user records
    | email          | password |
    | test@email.com | password |
  Given I am logged in as "test@email.com" with password "password"

Scenario: Edit existing note
  Given I have already created a note that belongs to current_user

general_steps.rb

Given /^the following (.+) records?$/ do |factory, table|
  table.hashes.each do |hash|
    Factory(factory, hash)
  end
end

Given /^I am logged in as "([^\"]*)" with password "([^\"]*)"$/ do |email, password|
  unless email.blank?
    visit new_user_session_path
    fill_in "Email", :with => email
    fill_in "Password", :with => password
    click_button "Sign In"
  end
end

note_steps.rb

  Given /^I have already created a (.+) that belongs to (.+)$/ do |factory, resource|
      model = Factory(factory)
      resource.send(model.class.to_s.downcase.pluralize) << model
  end

Seems like there might be a way to use the devise ‘current_user’ helper.

What is the correct way to accessing the user that is logged in?

Please let me know if you need more information.
Thanks!

UPDATE 1:
I have temporarily fixed my issue by creating a new step that allows me to do:

Given I have already created a note that is owned by the user with email "test@email.com"

But I don’t want to specify the email, I’d still like to be able to use the logged in user if possible.

UPDATE 2:
Added general_steps.rb

So you can see, that in my ‘Background’, the user is created via a Factory, and then is logged in via my interface. I want to access the model of that logged in User.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:11:22+00:00Added an answer on May 23, 2026 at 5:11 am

    I don’t use Devise, so I can’t answer specifically to if Devise has method of access the current_user.

    But I actually like to use Pickle to help me keep my references. And perhaps this can help you out till you find a more Devise specific way to achieve what you want.

    Given /^the following (.+) records$/ do |factory, table|
      table.hashes.each do |hash|
        Factory(factory, hash)
    
        # since this is like an all encompassing factory creator, this line to 
        # create a Pickle references might need a bit more extra work if you want
        # to create references for other factory types
    
        # I assume email is unique, else use a unique identifier of some sort
        find_model! %{user: "#{hash['email']}"}, {:email => hash['email']} 
      end
    end
    
    Given /^I have already created a (.+) that belongs to #{capture_model}$/ do |factory, name|
      model = Factory(factory)
      ref = model!(name) # we find that reference here
      ref.send(model.class.to_s.downcase.pluralize) << model
    end
    

    This would read

    Given I have already created a note that belongs to user: "test@email.com"
    
    # I would just change this to 
    Given I have already created a note
    
    # or
    Given a note was created for user: "test@email.com"
    

    You are I since you said Given I logged in..., no need to say that belongs to user: "test@email.com" it’s already you.

    Not to mention it could lead to confusion when you read it, some people may think you are adding a note to a user, who they might now know (or realize) is actually yourself.


    While you still have to reference explicitly (eg. user: “John Doe”), I think that is a plus. By always calling specific references, everyone knows who is being referenced and there is no question about who is doing what to what.

    Pickle serves us very well for this purpose. The only problematic areas we find are with things created directly through the app’s ui, which gets a bit tricky to ensure you are creating the right reference to it.

    Pickle has a large number of uses so definitely take a look.


    Upate

    You will have to find yourself here. Since, like you wanted, there is no current_user option (as far as we know). So you basically have to go find the “actor” in this scenario.

    Given /^I have already created a note$/ do
      user = model!(%{user: "test@email.com"}) # if using pickle
      # user = User.find_by_email("test@email.com") # if just regular AR
      user.notes << Note.create
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to JavaScript. Kindly note that I am trying below issue
Please note that I am very new to .NET and ASP.NET. I have a
Before reading, please note that I am very new to both PHP and MYSQL.
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
According to this : It is important to note that this is very different
I'm very new to this WPF technology, I started with a sticky note application
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
very new to crystal reports.. Question is that - In our .net application we
I'm a very new to C#. Just playing around with it. Not for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.