small medium large xlarge

Generic-user-small
30 Dec 2017, 21:19
Grzegorz (12 posts)

I can’t get the “Search by Name” test to pass. I have the: Failure/Error: click_button "Log in". I ran RAILS_ENV=test bin/webpack already. I checked the screenshot and the “Log in” button is there. I also save_and_open_page which gives me the input tag which click_button is looking for:

<!DOCTYPE html><html><head>
    ...
  </head>

  <body class="container">

        <aside class="alert alert-danger">
            You need to sign in or sign up before continuing.
        </aside>

    <h2>Log in</h2>

<form class="new_user" id="new_user" action="/users/sign_in" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓">
  <div class="form-group">
    ...
  </div>

  <div class="form-group">
    ...
  </div>

    <div class="field">
      ...
    </div>

  <div class="actions">
    <input type="submit" name="commit" value="Log in" class="btn btn-primary btn-lg" data-disable-with="Log in">
  </div>
</form>
  ...
</body></html>

I also tried to provide options to click_button like: click_button("Log in", options = {value: 'Log in'}) or click_button("Log in", options = {class: 'btn btn-primary btn-lg'}) but none of it helps.

What may be the problem?

Full error message is:

  Search by Name (FAILED - 1)

Failures:

  1) Customer Search Search by Name
     Failure/Error: click_button("Log in")
     
     Capybara::Poltergeist::JavascriptError:
       One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
     
       TypeError: undefined is not a function (evaluating 'Object.assign({}, merged, opt)')
       TypeError: undefined is not a function (evaluating 'Object.assign({}, merged, opt)')
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:25247
           at :0 in reduce
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:25247 in combine
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:25097
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:20 in __webpack_require__
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:17126
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:20 in __webpack_require__
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:60006
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:20 in __webpack_require__
           at http://127.0.0.1:34457/packs-test/customers-911865431f6d0e7a98a2.js:63
     # ./spec/features/customer_search_spec.rb:128:in `block (2 levels) in <top (required)>'

Top 1 slowest examples (7.45 seconds, 90.6% of total time):
  Customer Search Search by Name
    7.45 seconds ./spec/features/customer_search_spec.rb:118

Finished in 8.23 seconds (files took 4.71 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/features/customer_search_spec.rb:118 # Customer Search Search by Name
Dmfcb_pragsmall
30 Dec 2017, 22:15
David Copeland (511 posts)

Does it work in dev mode, i.e. if you run thre server and interact with the app in your browser?

The error message is saying that there’s an error from JavaScript, and usually if that happens during a test, it’s a problem just using the app, too.

Generic-user-small
31 Dec 2017, 12:07
Grzegorz (12 posts)

Yes. When I manually visit to /customers it redirects me to users/sign_in. There I can fill the email, password and click ‘Log in’. However I am being redirected to root localhost:5000/. Should it not redirect me back to /customers as the next line in test assume filling in keywords within section.search-form?

I tried that by placing visit "/customers" after click_button "Log in" hoping the spec somehow reached this line and reported one earlier, but the test is actually failing on click_button.

Output from my logs after clicking “Log in” in browser:

Started POST "/users/sign_in" for 127.0.0.1 at 2017-12-31 09:11:59 +0100
09:11:59 rails.1   | Processing by Devise::SessionsController#create as HTML
09:11:59 rails.1   |   Parameters: {"utf8"=>"✓", "authenticity_token"=>"KidXRcU+edjUUZ3nRSvVXn++uH2QKpQnruzTYYXAietg7k2dP645yAHEMrfk6pLHPjgsmZv6kgJRv8FrPd52MQ==", "user"=>{"email"=>"bar@example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
09:11:59 rails.1   |   User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["email", "bar@example.com"], ["LIMIT", 1]]
09:11:59 rails.1   |    (0.4ms)  BEGIN
09:11:59 rails.1   |   SQL (0.9ms)  UPDATE "users" SET "current_sign_in_at" = $1, "last_sign_in_at" = $2, "sign_in_count" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["current_sign_in_at", "2017-12-31 08:11:59.639372"], ["last_sign_in_at", "2017-12-31 08:11:44.837645"], ["sign_in_count", 11], ["updated_at", "2017-12-31 08:11:59.641429"], ["id", 8]]
09:11:59 rails.1   |    (24.8ms)  COMMIT
09:11:59 rails.1   | Redirected to http://localhost:5000/
09:11:59 rails.1   | Completed 302 Found in 287ms (ActiveRecord: 27.0ms)
09:11:59 rails.1   | 
09:11:59 rails.1   | 
09:11:59 rails.1   | Started GET "/" for 127.0.0.1 at 2017-12-31 09:11:59 +0100
09:11:59 rails.1   | Processing by DashboardController#index as HTML
09:11:59 rails.1   |   User Load (1.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 8], ["LIMIT", 1]]
09:11:59 rails.1   |   Rendering dashboard/index.html.erb within layouts/application
09:11:59 rails.1   |   Rendered dashboard/index.html.erb within layouts/application (1.4ms)
09:11:59 rails.1   | Completed 200 OK in 39ms (Views: 31.5ms | ActiveRecord: 1.0ms)

Ultimately I have copied the source code for customer_search_spec.rb, customer.js, customers_controller.rb, devise/sessions/new.html.erb but this doesn’t helped too.

EDIT: My version of webpacker is 3.2.0. Maybe this is the case. I tried to install ver. 2.6, as I remember is used in the book, but the only versions available at RubyGems are 2.0 and >= 3.0

Dmfcb_pragsmall
31 Dec 2017, 15:16
David Copeland (511 posts)

I’m not totally following what the problem is—in the first post there is a JS error, but now you are saying that auth is messed up and not redirecting you properly?

Can you post your current version of the app to GitHub so I can see the full thing?

Generic-user-small
31 Dec 2017, 15:52
Grzegorz (12 posts)

My main problem is that test is failing on click_button "Log in" and I don’t know why since it works fine while testing manually, and save_page is showing that there is <input type="submit" value="Log in">.

The redirecting thing is only my suspicion. It may be wrong suspicion.

My Repo

Dmfcb_pragsmall
31 Dec 2017, 16:05
David Copeland (511 posts)

The app you posted doesn’t have any tests. Is it possible you posted an older version?

Generic-user-small
31 Dec 2017, 16:08
Grzegorz (12 posts)

Sorry, I should mention this is the branch testing at github not master

Dmfcb_pragsmall
31 Dec 2017, 17:22
David Copeland (511 posts)

I pulled it down and cannot figure out why it’s not working. Does the code from the book work for you? If so, I would see what the differences are between what you have and what the books’ code has. It’s possible that updated versions of the javascript stuff have broken things—this is a frequent occurence so you may need to copy the yarn.lock from the book’s code so you use the exact same versions of things.

Generic-user-small
31 Dec 2017, 18:03
Grzegorz (12 posts)

Thank you for help. Unfortunately I can’t work on it further today because of new year night. Will be back to it ASAP. Hopefully tomorrow. Best wishes for you too and have a good party.

You must be logged in to comment