small medium large xlarge

Jruby_pragsmall
22 Mar 2017, 16:34
Serguei Cambour (14 posts)

I get this error when running customer_search_spec.rb after the latest modification as described on page 202. Running refresh_materialized_views rake task didn’t solve the issue. I even tried to refresh the view customer_details in shine_test DB manually from PgAdmin 4. FYI, I’m using Postgres 9.6.10. Here is the stack trace of the error:

Failures:

  1) Customer Search Search by Email
     Failure/Error: customer_detail = CustomerDetail.find(params[:id])
     
     ActiveRecord::StatementInvalid:
       PG::ObjectNotInPrerequisiteState: ERROR:  materialized view "customer_details" has not been populated
       HINT:  Use the REFRESH MATERIALIZED VIEW command.
       : SELECT  "customer_details".* FROM "customer_details" WHERE "customer_details"."customer_id" = $1 LIMIT $2

Any ideas ? Thank you.

Dmfcb_pragsmall
23 Mar 2017, 20:52
David Copeland (511 posts)

Hmmm. This does not happen for me, and it should succeed because you will have inserted data into the tables. Can you post your entire test file as well as the full stack trace?

Jruby_pragsmall
24 Mar 2017, 10:36
Serguei Cambour (14 posts)

Hi, David ! Here the spec file:


require 'rails_helper'

feature "Customer Search" do
  def create_customer(first_name:,
                      last_name:,
                      email: nil)

    username = "#{Faker::Internet.user_name}#{rand(1000)}"
    email  ||= "#{username}#{rand(1000)}@" +
               "#{Faker::Internet.domain_name}"

    customer = Customer.create!(
      first_name: first_name,
       last_name: last_name,
        username: username,
           email: email
    )

    customer.create_customers_billing_address(address: create_address)
    customer.customers_shipping_address.create!(address: create_address, primary: true)

    customer
  end

  def create_address
    state = State.find_or_create_by!(
      code: Faker::Address.state_abbr,
      name: Faker::Address.state)

    Address.create!(
      street: Faker::Address.street_address,
      city: Faker::Address.city,
      state: state,
      zipcode: Faker::Address.zip)
  end

  let(:email)    { "pat@example.com" }
  let(:password) { "password123" }

  before do
    User.create!(email: email,
                 password: password,
                 password_confirmation: password)

    create_customer first_name: "Chris",
                     last_name: "Aaron"

    create_customer first_name: "Pat",
                     last_name: "Johnson"

    create_customer first_name: "I.T.",
                     last_name: "Pat"

    create_customer first_name: "Patricia",
                     last_name: "Dobbs"

    create_customer first_name: "Pat",
                     last_name: "Jones",
                         email: "pat123@somewhere.net"
    visit "/customers"
    fill_in      "Email",    with: email
    fill_in      "Password", with: password
    click_button "Log in"
  end

  scenario "Search by Name" do
    within "section.search-form" do
      fill_in "keywords", with: "pat"
    end
    within "section.search-results" do
      expect(page).to have_content("Results")
      expect(page.all("ol li.list-group-item").count).to eq(4)

      expect(page.all("ol li.list-group-item")[0]).to have_content("Patricia")
      expect(page.all("ol li.list-group-item")[0]).to have_content("Dobbs")

      expect(page.all("ol li.list-group-item")[3]).to have_content("I.T.")
      expect(page.all("ol li.list-group-item")[3]).to have_content("Pat")
    end
  end

  scenario "Search by Email" do
    within "section.search-form" do
      fill_in "keywords", with: "pat123@somewhere.net"
    end

    within "section.search-results" do
      expect(page).to have_content("Results")
      expect(page.all("ol li.list-group-item").count).to eq(4)

      expect(page.all("ol li.list-group-item")[0]).to have_content("Pat")
      expect(page.all("ol li.list-group-item")[0]).to have_content("Jones")

      expect(page.all("ol li.list-group-item")[1]).to have_content("Patricia")
      expect(page.all("ol li.list-group-item")[1]).to have_content("Dobbs")

      expect(page.all("ol li.list-group-item")[3]).to have_content("I.T.")
      expect(page.all("ol li.list-group-item")[3]).to have_content("Pat")
    end

    click_on "View Details...", match: :first
    customer = Customer.find_by!(email: "pat123@somewhere.net")
    within "section.customer-details" do
      expect(page).to have_content(customer.id)
      expect(page).to have_content(customer.first_name)
      expect(page).to have_content(customer.last_name)
      expect(page).to have_content(customer.email)
      expect(page).to have_content(customer.username)
    end
  end
end

And here is the stack trace:

➜  shine git:(materialized_views) ✗ rspec spec/features/customer_search_spec.rb 
/Users/Serguei/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
/Users/Serguei/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
/Users/Serguei/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138: warning: constant ::Fixnum is deprecated
/Users/Serguei/.rvm/gems/ruby-2.4.0/gems/activejob-5.0.1/lib/active_job/arguments.rb:38: warning: constant ::Fixnum is deprecated
/Users/Serguei/.rvm/gems/ruby-2.4.0/gems/activejob-5.0.1/lib/active_job/arguments.rb:38: warning: constant ::Bignum is deprecated

Randomized with seed 48855

Customer Search
 http://localhost:3808/webpack-dev-server/
webpack result is served from //localhost:3808/webpack/
content is served from /Users/Serguei/projects/shine
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
  Search by Name
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
  Search by Email (FAILED - 1)
Killing webpack-dev-server

Failures:

  1) Customer Search Search by Email
     Failure/Error: expect(page).to have_content(customer.id)
       expected to find text "5" in "Customer Info First Name Last Name @ Email Joined12/13/2014 Shipping Address Street Address Street Address Extra City State Zip Billing Info ****-****-****-1234 VISA Expires: 04/19 View Details... Billing Address Same as shipping? Street Address Street Address Extra City State Zip"
     # ./spec/features/customer_search_spec.rb:104:in `block (3 levels) in <top (required)>'
     # /Users/Serguei/.rvm/gems/ruby-2.4.0/gems/capybara-2.12.0/lib/capybara/session.rb:310:in `within'
     # /Users/Serguei/.rvm/gems/ruby-2.4.0/gems/capybara-2.12.0/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
     # ./spec/features/customer_search_spec.rb:103:in `block (2 levels) in <top (required)>'

Top 2 slowest examples (8.03 seconds, 98.7% of total time):
  Customer Search Search by Name
    4.52 seconds ./spec/features/customer_search_spec.rb:66
  Customer Search Search by Email
    3.51 seconds ./spec/features/customer_search_spec.rb:82

Finished in 8.13 seconds (files took 2.46 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/features/customer_search_spec.rb:82 # Customer Search Search by Email

Randomized with seed 48855

Jruby_pragsmall
24 Mar 2017, 10:45
Serguei Cambour (14 posts)

I didn’t run it against your code, just followed the steps in the book, created my own branch, etc. I’m on Ruby 2.4.0, but don’t think it to be an issue.

Dmfcb_pragsmall
24 Mar 2017, 13:09
David Copeland (511 posts)

That is showing a different error than you originally posted. It looks like a “normal” test failure, that it can’t find the customer ID on the view. When you run the app, is the customer ID showing up on the view?

Jruby_pragsmall
24 Mar 2017, 15:58
Serguei Cambour (14 posts)

I can’t see it a browser. If I’m not mistaken, all the data is reset before each test run by database_cleaner. More of that, when starting a server, it runs in dev mode and not in test. We init the data in beforebloc of the feature spec:

create_customer first_name: "Pat",
                     last_name: "Jones",
                         email: "pat123@somewhere.net"

Then it fails on line 104:

expect(page).to have_content(customer.id)

when searching a customer by mail pat123@somewhere.net. It seems like the materialized view is not updated when using triggers.

Jruby_pragsmall
24 Mar 2017, 16:06
Serguei Cambour (14 posts)

I’ve just checked out the code source for that chapter. And the corresponding part of code in customer_search_spec is commented out:

within "section.customer-details" do
      # commenting out since our mockup is just static at this point
      # expect(page).to have_content(customer.id)
      # expect(page).to have_content(customer.first_name)
      # expect(page).to have_content(customer.last_name)
      # expect(page).to have_content(customer.email)
      # expect(page).to have_content(customer.username)
    end
Dmfcb_pragsmall
24 Mar 2017, 16:05
David Copeland (511 posts)

I guess I’m confused about why you think the materialized view is the issue. It looks like your test is simply failing, but it’s hard to tell for sure, because I can’t see your app’s source code. Can you post it somewhere?

The reason I suggested trying the code in a browser in dev mode is to make sure that the app is actually working properly and that the test failure isn’t just detecting a legit bug in your code.

Jruby_pragsmall
25 Mar 2017, 21:00
Serguei Cambour (14 posts)

David, you can check the code source from my github repo.

Thank you and regards.

Dmfcb_pragsmall
26 Mar 2017, 16:55
David Copeland (511 posts)

OK, wow, this is a weird one. I’m not sure how I never encountered this, but I’ll update the book about!

What was confusing is that your test setup inserts into the various tables, which should execute the trigger and thus update the view.

That works as long as the view has ever been materialized. In your case, the very first time, the view won’t have been created ever and the trigger errors out. Since the trigger swallows all errors, it just silently fails.

SO

Try this locally:

> RAILS_ENV=test bundle exec rails dbconsole # note we are using test env
shine_test=# refresh materialized view customer_details;

THEN, your tests should work.

Jruby_pragsmall
27 Mar 2017, 12:18
Serguei Cambour (14 posts)

Cool ! David, thank you very much, it worked as expected.

2012-08-16-102302_pragsmall
20 Jun 2017, 11:39
Michael Pope (10 posts)

I’ve also got this problem and I’ve been working through the book also.

I’ve tried the suggested command to refresh the materialized view but that didn’t help, even though I ran the test straight after;

> RAILS_ENV=test bundle exec rails dbconsole # note we are using test env
shine_test=# refresh materialized view customer_details;
  1) Customer Search Search by Email
     Failure/Error: expect(page).to have_content(customer.id)
       expected to find text "5" in "Customer First Name Last Name Username @ Email Joined 12/13/2014 Shipping Address Street Address City State Zip Billing Info ****-****-****-1234 VISA Expires: 04/19 View Details... Billing Address Same as shipping? Street Address City State Zip"
     # ./spec/features/customer_search_spec.rb:122:in `block (3 levels) in <top (required)>'
     # ./spec/features/customer_search_spec.rb:119:in `block (2 levels) in <top (required)>'

Finished in 11.66 seconds (files took 1.48 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/features/customer_search_spec.rb:91 # Customer Search Search by Email

I’ve copied the test from the book and noticed the section which I have a problem with is skipped

    within "section.customer-details" do
      warn "YOU ARE SKIPPING TESTS!"
      if false
      expect(page).to have_content(customer.id)
      expect(page).to have_content(customer.first_name)
      expect(page).to have_content(customer.last_name)
      expect(page).to have_content(customer.email)
      expect(page).to have_content(customer.username)
      end
    end

If I remove the warning and the if statement and run this test I get the same result as my code.

I’ve put my code up on github: https://github.com/map7/shine.git

Dmfcb_pragsmall
20 Jun 2017, 12:38
David Copeland (511 posts)

It looks like you are using a pretty old version of the book. I believe that at this point in the book, the tests are disabled because the UI is still being built.

The error you posted doesn’t seem to have anything to do with materialized views. It’s complaining that it can’t find the customer’s ID, but your view isn’t rendering it: https://github.com/map7/shine/blob/master/webpack/CustomerDetailsComponent.html

Could be the text is out of date, but as I said, you seem to be using a pretty old version of the book, as many things about the Angular stuff have change d in the recent betas.

2012-08-16-102302_pragsmall
24 Sep 2017, 07:49
Michael Pope (10 posts)

I’ve worked through the latest version of the book (p1) up to this point from scratch and still get the same issue. I think all that’s missing in the book is to skip that part of the test for now until I update the view.

Dmfcb_pragsmall
24 Sep 2017, 13:31
David Copeland (511 posts)

If the error message is the same and the code looks like the link above, the problem is that your test is expecting the customer id, but it is not being rendered in the view.

If that’s not wahts’ happening, can you post the error you are getting and a link to your latest code?

Generic-user-small
18 Dec 2017, 22:09
Ryan Pool (14 posts)

I’m having the same problems as Michael Pope. I have pushed up my code to Github at https://github.com/ryanpool/shine.

Using a sleep timer I was able to prove that values are being written into my materialized view, so I know that’s not the problem. My dev environment works perfectly, but test does not.

I added an inspect to the Rails customer_controller#show method and see that Rails found a customer. I added a puts page.html inside the within “section.customer-details” inside customer search spec and discovered that none of the values are being added to the page.

I would like to mention that the code download, both the zip and the tgz, include the code from customer_search_spec.rb that prompted David to say he was working from an old copy of the book. I know I’m working from version P1. The book doesn’t include the code for this file in an appendix so I used my copy of downloaded code to validate what I had. I remember we added the expect(page).to have_content(customer.id) early on in the process of writing customer the customer details page. I don’t believe that any part of the book asks us to remove that expectation.

Here is the output from puts page.html.

<!DOCTYPE html><html><head>
    <title>Shine</title>
    

    <link rel="stylesheet" media="all" href="/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css">
    <script src="/assets/application-68c34e3c02a436aeb143ba578224a1086b72f086ef00e273b08133ebb9f249ab.js"></script>
    <script src="/packs-test/application-adeac507863b6b0f3b07.js"></script>
    <link rel="stylesheet" media="screen" href="/packs-test/application-d97b1079065ed5f66012e5679794e5e2.css">
      <base href="/customers/ng">
  </head>

  <body class="container">
      <aside class="alert alert-info">
        Signed in successfully.
      </aside>
    <section>
  <shine-customers-app ng-version="4.4.6"><router-outlet></router-outlet><shine-customer-details><!--bindings={
  "ng-reflect-ng-if": "[object Object]"
}--><section class="customer-details"> <form novalidate="" class="ng-untouched ng-pristine ng-valid"><div class="row"> <div class="col-md-6"> <article class="panel panel-primary"> <header class="panel-heading"> <h1>Customer Details</h1> </header> <section class="panel-body"> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label class="sr-only" for="first-name">First Name</label> <input class="form-control" name="first-name" type="text"> </div> </div> <div class="col-md-3"> <div class="form-group"> <label class="sr-only" for="last-name">Last Name</label> <input class="form-control" name="last-name" type="text"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="username">Username</label> <div class="input-group"> <div class="input-group-addon">@</div> <input class="form-control" name="username" type="text"> </div> </div> </div> </div> <div class="form-group"> <label class="sr-only" for="email">Email</label> <input class="form-control" name="email" type="text"> </div> </section> <footer class="panel-footer"> <label for="joined">Joined</label>  </footer> </article> <article class="panel panel-default"> <header class="panel-header"> <h2>Shipping Address</h2> </header> <section class="panel-body"> <div class="form-group"> <label class="sr-only" for="street-address">Street Address</label> <input class="form-control" name="street-address" type="text" value="123 Any St"> </div> <div class="form-group"> <label class="sr-only" for="street-address-extra">Street Address Extra</label> <input class="form-control" name="street-address-extra" type="text" value="Unit 101"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="city">City</label> <input class="form-control" name="city" type="text" value="Washington"> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="sr-only" for="state">State</label> <input class="form-control" name="state" type="text" value="DC"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="sr-only" for="zip">Zip</label> <input class="form-control" name="zip" type="text" value="20001"> </div> </div> </div> </section> </article> </div> <div class="col-md-6"> <article class="panel panel-default"> <header class="panel-header"> <h2 class="h4">Billing Info</h2> </header> <section class="panel-body"> <div class="row"> <div class="col-md-7"> <p class="h4"> ****-****-****-1234 <span class="label label-success">VISA</span> </p> <p> <label>Expires:</label> 04/19 </p> </div> <div class="col-md-5 text-right"> <button class="btn btn-lg btn-default">View Details...</button> </div> </div> <h3>Billing Address <input type="checkbox"> Same as shipping? </h3> <div class="form-group"> <label class="sr-only" for="street-address">Street Address</label> <input class="form-control" name="street-address" type="text" value="123 Any St"> </div> <div class="form-group"> <label class="sr-only" for="street-address-extra">Street Address Extra</label> <input class="form-control" name="street-address-extra" type="text" value="Unit 101"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="city">City</label> <input class="form-control" name="city" type="text" value="Washington"> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="sr-only" for="state">State</label> <input class="form-control" name="state" type="text" value="DC"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="sr-only" for="zip">Zip</label> <input class="form-control" name="zip" type="text" value="20001"> </div> </div> </div> </section> </article> </div> </div></form> </section> </shine-customer-details></shine-customers-app>
</section>
<script src="/packs-test/customers-a14a77d121ea8aba5875.js"></script>

Any advice welcome.

Thanks, Ryan

Dmfcb_pragsmall
18 Dec 2017, 22:53
David Copeland (511 posts)

I’m on a new computer and don’t have Postgres 9.6 set up right now. Your code looks right. Are you certain that the materialized view is being refreshed? You should be able to query CustomerDetail directly inside your test to verify.

Generic-user-small
18 Dec 2017, 23:45
Ryan Pool (14 posts)

I will add a query to the test so I can say I did. I’ve already verified a different way though.

I added a sleep 60 to the test and while the test was sleeping used rails dbconsole test to get in and look around. Here’s what I have from two different tests:

shine_test=> select * from customer_details;
 customer_id | first_name | last_name |               email                |      username      |         joined_at          | billing_address_id |   billing_street    |   billing_city    | billing_state | billing_zipcode | shipping_address_id |    shipping_street     |  shipping_city   | shipping_state | shipping_zipcode 
-------------+------------+-----------+------------------------------------+--------------------+----------------------------+--------------------+---------------------+-------------------+---------------+-----------------+---------------------+------------------------+------------------+----------------+------------------
           1 | Chris      | Aaron     | elia633760@harveybrekke.biz        | elia633            | 2017-12-18 20:34:29.960018 |                  1 | 144 Lind Garden     | Port Fridaberg    | AL            | 46810-3386      |                   2 | 791 Ratke Cliffs       | Lake Roberto     | NJ             | 42710
           2 | Pat        | Johnson   | kayley.nitzsche581927@collier.co   | kayley.nitzsche581 | 2017-12-18 20:34:30.070266 |                  3 | 260 Jacobi Bypass   | West Crystalhaven | MS            | 32534           |                   4 | 6797 Larkin Summit     | New Leilani      | SD             | 69974-7510
           3 | I.T.       | Pat       | hilton100117@yundt.org             | hilton100          | 2017-12-18 20:34:30.179487 |                  5 | 4765 Trantow Glens  | Janaeshire        | AL            | 85785-0893      |                   6 | 856 Amari Light        | East Dawson      | IA             | 31396-1539
           4 | Patricia   | Dobbs     | shania_conroy80250@kautzerkris.org | shania_conroy80    | 2017-12-18 20:34:30.262161 |                  7 | 35119 Cummerata Rue | Langoshborough    | AK            | 28134           |                   8 | 3400 Freeda Union      | East Rosaleebury | ND             | 22976-0913
           5 | Pat        | Jones     | pat123@somewhere.net               | darian887          | 2017-12-18 20:34:30.402185 |                  9 | 532 Noelia Mills    | North Shyanne     | UT            | 67293           |                  10 | 57695 Kallie Junctions | Schambergerport  | OK             | 24546
(5 rows)

shine_test=> select * from customer_details;
 customer_id | first_name | last_name |               email                |     username      |         joined_at          | billing_address_id |    billing_street     |  billing_city  | billing_state | billing_zipcode | shipping_address_id |   shipping_street    | shipping_city  | shipping_state | shipping_zipcode 
-------------+------------+-----------+------------------------------------+-------------------+----------------------------+--------------------+-----------------------+----------------+---------------+-----------------+---------------------+----------------------+----------------+----------------+------------------
           1 | Chris      | Aaron     | damon264665@gerhold.name           | damon264          | 2017-12-18 21:03:54.038302 |                  1 | 1619 Luna Cliff       | Douglasborough | WI            | 83049           |                   2 | 78554 Eryn Hills     | MacGyverhaven  | MN             | 91927
           2 | Pat        | Johnson   | amparo766749@huels.co              | amparo766         | 2017-12-18 21:03:54.314184 |                  3 | 95740 McClure Point   | South Werner   | SD            | 15820           |                   4 | 395 Macejkovic Dale  | Cliftonburgh   | MD             | 50701
           3 | I.T.       | Pat       | titus_thompson110792@gusikowski.co | titus_thompson110 | 2017-12-18 21:03:54.396546 |                  5 | 24785 Witting Ways    | Osinskishire   | KS            | 27365           |                   6 | 8247 Treutel Points  | Elissaton      | NH             | 93489-6288
           4 | Patricia   | Dobbs     | letitia.kihn439476@fisher.info     | letitia.kihn439   | 2017-12-18 21:03:54.483864 |                  7 | 4039 Gaylord Crescent | Creminview     | ME            | 95170-7160      |                   8 | 54070 Hahn Lane      | Meaganview     | TX             | 21208-0697
           5 | Pat        | Jones     | pat123@somewhere.net               | omari504          | 2017-12-18 21:03:54.570497 |                  9 | 8355 Araceli Cove     | Terryport      | OH            | 11032-0861      |                  10 | 9437 Nitzsche Island | Port Milesfort | TX             | 99343
(5 rows)

Thanks for the fast response!

Ryan

Edit To Add - Here’s the output from the last test. I added CustomerDetail.find_by!(email: ‘pat123@somewhere.net’).inspect to generate this output.

customer_details for pat123@somewhere.net
#<CustomerDetail customer_id: 5, first_name: "Pat", last_name: "Jones", email: "pat123@somewhere.net", username: "clay_corwin831", joined_at: "2017-12-18 23:41:57", billing_address_id: 9, billing_street: "432 Elton Fork", billing_city: "Lake Liliane", billing_state: "NJ", billing_zipcode: "72044", shipping_address_id: 10, shipping_street: "3267 Nolan Mountains", shipping_city: "O'Harastad", shipping_state: "CA", shipping_zipcode: "22291-5560">
<!DOCTYPE html><html><head>
    <title>Shine</title>
    

    <link rel="stylesheet" media="all" href="/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css">
    <script src="/assets/application-68c34e3c02a436aeb143ba578224a1086b72f086ef00e273b08133ebb9f249ab.js"></script>
    <script src="/packs-test/application-adeac507863b6b0f3b07.js"></script>
    <link rel="stylesheet" media="screen" href="/packs-test/application-d97b1079065ed5f66012e5679794e5e2.css">
      <base href="/customers/ng">
  </head>

  <body class="container">
      <aside class="alert alert-info">
        Signed in successfully.
      </aside>
    <section>
  <shine-customers-app ng-version="4.4.6"><router-outlet></router-outlet><shine-customer-details><!--bindings={
  "ng-reflect-ng-if": "[object Object]"
}--><section class="customer-details"> <form novalidate="" class="ng-untouched ng-pristine ng-valid"><div class="row"> <div class="col-md-6"> <article class="panel panel-primary"> <header class="panel-heading"> <h1>Customer Details</h1> </header> <section class="panel-body"> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label class="sr-only" for="first-name">First Name</label> <input class="form-control" name="first-name" type="text"> </div> </div> <div class="col-md-3"> <div class="form-group"> <label class="sr-only" for="last-name">Last Name</label> <input class="form-control" name="last-name" type="text"> </div> </div> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="username">Username</label> <div class="input-group"> <div class="input-group-addon">@</div> <input class="form-control" name="username" type="text"> </div> </div> </div> </div> <div class="form-group"> <label class="sr-only" for="email">Email</label> <input class="form-control" name="email" type="text"> </div> </section> <footer class="panel-footer"> <label for="joined">Joined</label>  </footer> </article> <article class="panel panel-default"> <header class="panel-header"> <h2>Shipping Address</h2> </header> <section class="panel-body"> <div class="form-group"> <label class="sr-only" for="street-address">Street Address</label> <input class="form-control" name="street-address" type="text" value="123 Any St"> </div> <div class="form-group"> <label class="sr-only" for="street-address-extra">Street Address Extra</label> <input class="form-control" name="street-address-extra" type="text" value="Unit 101"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="city">City</label> <input class="form-control" name="city" type="text" value="Washington"> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="sr-only" for="state">State</label> <input class="form-control" name="state" type="text" value="DC"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="sr-only" for="zip">Zip</label> <input class="form-control" name="zip" type="text" value="20001"> </div> </div> </div> </section> </article> </div> <div class="col-md-6"> <article class="panel panel-default"> <header class="panel-header"> <h2 class="h4">Billing Info</h2> </header> <section class="panel-body"> <div class="row"> <div class="col-md-7"> <p class="h4"> ****-****-****-1234 <span class="label label-success">VISA</span> </p> <p> <label>Expires:</label> 04/19 </p> </div> <div class="col-md-5 text-right"> <button class="btn btn-lg btn-default">View Details...</button> </div> </div> <h3>Billing Address <input type="checkbox"> Same as shipping? </h3> <div class="form-group"> <label class="sr-only" for="street-address">Street Address</label> <input class="form-control" name="street-address" type="text" value="123 Any St"> </div> <div class="form-group"> <label class="sr-only" for="street-address-extra">Street Address Extra</label> <input class="form-control" name="street-address-extra" type="text" value="Unit 101"> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="city">City</label> <input class="form-control" name="city" type="text" value="Washington"> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="sr-only" for="state">State</label> <input class="form-control" name="state" type="text" value="DC"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="sr-only" for="zip">Zip</label> <input class="form-control" name="zip" type="text" value="20001"> </div> </div> </div> </section> </article> </div> </div></form> </section> </shine-customer-details></shine-customers-app>
</section>
<script src="/packs-test/customers-1f26bf93bab60abf8cd1.js"></script>

  

</body></html>
F.

Failures:

  1) Customer Search Search by Email
     Failure/Error: expect(page).to have_content(customer.first_name)
       expected to find text "Pat" in "Customer Details First Name Last Name Username @ Email Joined Shipping Address Street Address Street Address Extra City State Zip Billing Info ****-****-****-1234 VISA Expires: 04/19 View Details... Billing Address Same as shipping? Street Address Street Address Extra City State Zip"
     # ./spec/features/customer_search_spec.rb:122:in `block (3 levels) in <top (required)>'
     # /Users/ryanpool/.rvm/gems/ruby-2.4.1@rails5/gems/capybara-2.16.1/lib/capybara/session.rb:343:in `within'
     # /Users/ryanpool/.rvm/gems/ruby-2.4.1@rails5/gems/capybara-2.16.1/lib/capybara/dsl.rb:50:in `block (2 levels) in <module:DSL>'
     # /Users/ryanpool/.rvm/gems/ruby-2.4.1@rails5/gems/capybara-2.16.1/lib/capybara/rspec/matcher_proxies.rb:14:in `within'
     # ./spec/features/customer_search_spec.rb:115:in `block (2 levels) in <top (required)>'
Dmfcb_pragsmall
19 Dec 2017, 13:24
David Copeland (511 posts)

Oh, I didn’t scroll over enough in your output to understand what’s happening.

Your template and view are all working—it’s just that the template isn’t rendering the customer’s ID. You can add something like {{customer.id}} inside the markup and the test should pass, but in the next section you should add the dynamic bits and fix up the test.

Sorry for the confusion :(

Generic-user-small
19 Dec 2017, 16:31
Ryan Pool (14 posts)

David,

I think the confusion is that the dynamic bits are supposed to be there. Here’s my code for customer first name:

input type="text" class="form-control" name="first-name" value="{{customer.first_name}}"

Here is my ngOnInit:

    ngOnInit: function() {
        var self = this;
        var observableFailed = function(response) {
            alert(response);
        };
        var customerGetSuccess = function(response) {
            self.customer = response.json().customer;
            alert(response.json().customer.last_name);
        };
        var routeSuccess = function(params) {
            self.http.get(
                "/customers/" + params["id"] + ".json"
            ).subscribe(
                customerGetSuccess,
                observableFailed
            );
        };
        self.activatedRoute.params.subscribe(routeSuccess, observableFailed);
    }

I get a popup with the customer’s last name so I know data is coming in from Rails, but it doesn’t make it into the view.

Previously my development environment was working but my test environment wasn’t. Now both are failing so it’s more consistent. I’m starting to think the problem is with webpack compiling my packs. Public/packs and public/packs-test do not match. If I wipe out the packs folders and try to regenerate them with webpack I get what seems like different results every time. This last time my public/packs directory has folders instead of application-.js files with an application-.js.map file inside the directory.

I’ve just updated my GitHub repository with the current pack directories. I’m not sure I can explain what I’m seeing very well so please take a look. https://github.com/ryanpool/shine

Thank you, Ryan

You must be logged in to comment