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 8460439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:36:28+00:00 2026-06-10T13:36:28+00:00

We have a Style model with dynamic attributes , which can be saved by

  • 0

We have a Style model with dynamic attributes, which can be saved by filling one field with the attribute key and the next field with the value.

A typical params hash looks like this:

{"utf8"=>"✓", "style"=>{"collection_id"=>"48", "program_id"=>"989", "number"=>"454632", "name"=>"t67f", "category_id"=>"19", "field_KEY"=>"VALUE"}, "commit"=>"save", "id"=>"4521"}

This works as intended when clicking it through, and the "field_KEY" => "VALUE" pair creates a new dynamic attribute with a getter(field_KEY) and setter(field_KEY=) method.

The Problem is: If the process is simulated with cucumber, something calls the getters for all keys in the hash before the attributes are set, including field_KEY.

Normal attributes will return nil for a new record, but since the getter for field_KEY has not yet been created, this results in an

`UndefinedMethodError: undefined method 'field_KEY'`.

Now my question: would you rather track down the caller of the field_KEY getter and mess around with cucumber, or should I try to simulate a fake method, something like:

def check_method(method_name)
    if method_name =~ /^field_/
       nil
    else
       ... # let the Error be raised
end

Better ideas or solutions are more than welcome

Thanks

  • 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-06-10T13:36:30+00:00Added an answer on June 10, 2026 at 1:36 pm

    The Problem was:

    The call to field_KEY came from pickle, because I included the step

    And the style's "field_KEY" should be "VALUE"
    

    which looks like this:

    Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
      actual_value  = model(name).send(attribute)
      expectation   = expectation.gsub(' ', '_')
    
      case expected
      when 'nil', 'true', 'false'
        actual_value.send(expectation, send("be_#{expected}"))
      when /^[+-]?[0-9_]+(\.\d+)?$/
        actual_value.send(expectation, eql(expected.to_f))
      else
        actual_value.to_s.send(expectation, eql(eval(expected)))
      end
    end
    

    I still don’t know why the dynamic_attribute getter had not been created up to this point.

    What I ended up doing:

    In my opinion (also, it solved the problem ;)), cucumber tests should be black-box tests, thats why I chose to change the steps and now I use

    And   the "key1" field should contain "KEY"
    

    which checks if the field has been filled with the correct value after the page reloads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this style: <Style x:Key=SelectableListBoxItemStyle TargetType={x:Type ListBoxItem}> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType={x:Type ListBoxItem}>
In emberJS, I have a model with an object property called style. I can
I have the following code to generate a table listing brand/model/submodel/style for a group
We have a model with properties decorated with [Required] which works great for validation.
I have a dynamic table like: <tbody> <% foreach (var item in Model) {
I have a Model, Customers , in which I have a list property, PayHistory
Lets say I have a function in my model, that generates a style tag
i have a dropdownlist: <%= Html.DropDownListFor(model => model.OperatingSystem, Model.OperatingSystemDropDownBowValues, new { style = width:142px;
I have a list box in my page.. <td><%=Html.ListBox(listServiceTypes, Model.ServiceTypeListAll, new { style =
let's say we have a model called Student and it has a string field

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.