Giter VIP home page Giter VIP logo

return-string-data-lab's Introduction

Returning Strings Lab

Objectives

  • Return a string from a route.
  • Use that string and replace the inner HTML of a div.

Introduction

Included in the lab is a simple Order/Invoice/Customer application. We're going to use what we've learned so far to add API endpoints and use AJAX to bring data to the page.

Instructions

  1. Add a product description and an inventory count to the Product model.
  2. Create an index page for all products that displays name and a truncated description, but not inventory.
  3. Create the new product page so you can add new products, otherwise the rest of this might be kind of underwhelming!
  4. Add a route and action that gets just a product description as a plain string.
  5. Add another route and action that checks if inventory is available. This route should return just "true" or "false" as strings.
  6. Add a "More Info" button to each product that, when clicked, fetches the description and the inventory and displays the result. If there is inventory available, display "Available" and if there isn't, display "Sold Out".
  7. Make sure tests pass!

PhantomJS Errors

If you receive this error:

Could not find an executable ["phantomjs"] on your path.

You'll need to install PhantomJS on your computer before the tests will work.

For Mac users, run the following:

brew cask install phantomjs

For Windows users, run the following:

npm install -g phantomjs-prebuilt

You can confirm the installation has worked by running phantomjs -v.

return-string-data-lab's People

Contributors

cernanb avatar dependabot[bot] avatar drakeltheryuujin avatar gj avatar jilustrisimo avatar lizbur10 avatar maxwellbenton avatar pletcher avatar rrcobb avatar scottcreynolds avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

return-string-data-lab's Issues

Seeds file should include product descriptions

The seeds file does not include any product descriptions, which makes it difficult to verify that the "More Info" button for products works correctly.

I would recommend using Faker::Lorem (or similar) to generate fake descriptions for each product in the seeds file.

Reported by @nicoleeidi.

Can't use ES6 syntax

It took me about three hours to solve this lab, even though it was working in the browser within about 20 minutes. The first issue is solved with Poltergeist, but it still will not work (and will not give any descriptive error) if you use ES6 syntax. That includes template strings (a.k.a. `like ${this}`).

So, before you tear your hair out for hours wondering what's going wrong, check that you aren't using backticks, let, const, etc.

Rails Gem Update

This app was forked with gem 'rails', '4.2.5' but with that gem there are a few deprecated dependencies - Errors are thrown when running rspec. Upgrading to gem 'rails', '4.2.8' seems to have solved the problem.

This isn't the first lab I've run into this issue is there any feedback on what is causing the hiccup?

Feature test appears to be broken

The feature test that tests the function of the more button in the index does not appear to work properly. The content on the page does not appear to update after the More Info button has been clicked by the test suite.

Issues with schema, tests, and seeds

It's not you. This lab has a ton of issues not at all related to the curriculum. It's frustrating, but let me try to save you some pain.

Most of them are covered below, but here's what I wish I had known when I started:

-You're going to need to create inventory and description fields in your product schema. Go ahead and do that. (Weirdly, this isn't in the solution--no idea how it is supposed to work without those tho!)

  • You'll need to make the change Ashely suggests below in three different places--in your seeds, and in both files in your view spec. (In short, you need to add the to and from keys for Faker::Number like so: Faker::Number.between(from: 1,to: 1500)

-No seeds for inventory or description are included. It's very hard to test out what you are doing without it! I'd recommend writing the following seed:
Product.create(:name => products.sample, :price => Faker::Number.between(from: 1, to: 100), :description => Faker::Lorem.sentence(word_count: 3, supplemental: true, random_words_to_add: 4).chop, :inventory => Faker::Number.between(from: 1, to: 20))

Good luck!

test passed using only var

in the view/products/index.html.erb file, the code only passed the test using var not let. Shouldn't let be used rather than var?

Selenium webdriver not working; causing tests to fail

A student passed all the tests in this lab, but when running the test suite (in the IDE), it would freeze up on the ProductsController / Products Index test section, and then spit out an error about requiring the Gecko driver for FireFox:

Selenium::WebDriver::Error::WebDriverError:                                                                                                                                           
Unable to find Mozilla geckodriver. Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. 
More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver.

Also got a similar Selenium error when running the solution branch, about port 7504 being locked up. The test would timeout after 45 seconds:

Selenium::WebDriver::Error::WebDriverError:                                                                                                                                           
       unable to bind to locking port 7054 within 45 seconds  

The student had one failing test.

Adding the poltergeist gem seemed to fix this.

gem 'poltergeist'

And add this to the spec/rails_helper.rb file:

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

After making the changed all of the student's tests passed .

Selenium::WebDriver::Error::WebDriverError:

ERROR:
Selenium::WebDriver::Error::WebDriverError:
unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)
I have Firefox installed, working and updated.
I have all but 1 test passing and consistently get the above error.
I have tried to update Selenium Web Driver, but it says "nothing to update".
I have tried running the tests with the 'Solution' code, and it produces the same error
I have tried "gem update selenium-webdriver", no change, same error.

Finally, I have tried to run the tests by commenting out the one below, no change, same error.
...../spec/features/product_feature_spec.rb

require 'rails_helper'

RSpec.describe "Product Index", type: :feature do
before do
Product.destroy_all
end

it 'gets the description and inventory', js: true do

product = Product.create!(name: "Test Product", inventory: 0, description: "This is a test description with more text than should be there.")

visit products_path

expect(page).to have_content product.name

expect(page).not_to have_content product.description

click_button "More Info"

expect(page).to have_content product.description

expect(page).to have_content "Sold Out"

product.inventory = 1

product.save

visit products_path

click_button "More Info"

expect(page).to have_content "Available"

end

end

No static controller built out for this lab (config/routes.rb)

Rails.application.routes.draw do

there is no static controller, comment out or remove it altogether?

get 'home', to: 'static#home'

resources :orders
resources :invoices
resources :products

get 'products/:id/description' => 'products#description'
get 'products/:id/inventory' => 'products#inventory'
end

phantomjs dependency issue

for test
rspec ./spec/features/product_feature_spec.rb:8 # Product Index gets the description and inventory
gives phantomjs dependency error

KNOWN ISSUES

PROBLEM: Issues with schema, tests, and seeds #21
NOTIFY: @stefclaus

PROBLEM: Faker::Number.between accepts key value arguments #20
NOTIFY: @Saturn226

PROBLEM: phantomjs dependency issue #19
NOTIFY: @daschne8

PROBLEM: test passed using only var Test #17
NOTIFY: @SallyZ12

PROBLEM: Requirement for number 6 in the lab #16
NOTIFY: @jmulloy

PROBLEM: No static controller built out for this lab (config/routes.rb) #15
NOTIFY: @JulJen

PROBLEM: seed should include :description and :inventory attributes #14 #11
NOTIFY: @DGMarkel @ivalentine

PROBLEM: Product Feature Spec Doesn't Click Button #12
NOTIFY: @tpetersen0308

PROBLEM: Feature test appears to be broken #10
NOTIFY: @f3mshep

PROBLEM: Tests in Product Feature Spec do not recognize jQuery Curriculum #9
NOTIFY: @jmstrick93

PROBLEM: Can't use ES6 syntax Curriculum #6
NOTIFY: @kjleitz

Faker::Number.between accepts key value arguments

As of v2.0, Faker::Number.between accepts key value arguments that currently breaks the test.

spec/views/invoices_index_view_spec.rb line: 11
spec/views/ orders_index_view_spec.rb line: 10

Need to be updated to

  Product.create(:name => products.sample, :price => Faker::Number.between(from: 1, to: 1500))

Requirement for number 6 in the lab

The #6 in the lab is straightforward when reading the lab at first. However, after getting started on it (especially compared to the previous lesson), I would separate the requirements for that one test into separate tests. The test is looking for perfect code for inventory and description that have different pieces of functionality in the application. If they were separate a student could work on description and get that passing then move on to work on displaying the inventory messages based on the count set up in the inventory method. Having the 2 pieces of functionality tied to the same test was resulting in looking for an issue with code that was working fine but the error was misleading.

Thanks!

Here's how to fix the testing error

The tests return this error:
Selenium::WebDriver::Error::WebDriverError: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

To fix this, do the following:

  1. In the gemfile, add: gem 'poltergeist'
  2. In the spec/rails_helper.rb file, add these two lines:
    require 'capybara/poltergeist'
    Capybara.javascript_driver = :poltergeist

Props to @cassaram09 for figuring this out in the first issue.

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.