Giter VIP home page Giter VIP logo

simple-partials-lab's Introduction

Simple Partials Lab

Objectives

  1. Use the render method to render partials
  2. Understand how the name of a partial turns into its filename
  3. Practice rendering partials in a different folder

Overview

Flatiron is building out a new system to keep track of students in its classes. You just joined the technical team and see that there's lots of repetition in the view layer of the code base. Use your new knowledge of partials to remove the duplication.

Instructions

First, fork and clone the lab.

We've provided a seed file so you can have some data to play around with. Run rake db:seed to seed the database.

  1. Remove the duplicated code in the students/edit.html.erb and students/new.html.erb files by making a partial called students/_form.html.erb.
  2. Remove the duplicated code in the classrooms/show.html.erb and students/show.html.erb files by making a partial called students/_student.html.erb.

simple-partials-lab's People

Contributors

annjohn avatar blake41 avatar curiositypaths avatar danielseehausen avatar drakeltheryuujin avatar franknowinski avatar ihollander avatar jeffkatzy avatar jmburges avatar kkterai avatar maxwellbenton avatar ritchey0713 avatar

Watchers

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

simple-partials-lab's Issues

Non-repeatable testing due to Faker

What I believe is an unintended consequence of using Faker::Name.name is that it occasionally generates an apostrophe in the name. In the way the form gets rendered, the apostrophe becomes an alt-code like so:

  • Name: Bria O'Connell

Diff:
@@ -1,2 +1,67 @@

-Bria O'Connell
While I am not certain this isn't intentional, it is a non-repeatable test.

RSpec.describe "classroom_show_view" do
let(:classroom) { Classroom.create(course_name: 'Math', semester: "Spring #{Time.now.year}") }
let(:student){ Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago)) }

before do
5.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
end

Problems with the Faker gem

Both the seeds.rb file and the relevant rspec files need to have all references to Faker changed so that the portion about Faker::Date has the words "from:" and "to:" included in the between arguments as shown below.

Faker::Date.between(from: 25.years.ago, to: 18.years.ago)

Faker gem 2.0 release breaks rake db:seed task

I get the following error message when running rake db:seed in this lab:

thomas.gray:~/flatiron/labs/simple-partials-lab-v-000 [git: master] $ rake db:seed
rake aborted!
ArgumentError: missing keywords: from, to
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/faker-2.2.1/lib/faker/default/date.rb:6:in `between'
/Users/thomas.gray/flatiron/labs/simple-partials-lab-v-000/db/seeds.rb:9:in `block in <top (required)>'
/Users/thomas.gray/flatiron/labs/simple-partials-lab-v-000/db/seeds.rb:8:in `times'
/Users/thomas.gray/flatiron/labs/simple-partials-lab-v-000/db/seeds.rb:8:in `<top (required)>'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `block in load'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:259:in `load_dependency'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:287:in `load'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/railties-5.0.7.2/lib/rails/engine.rb:549:in `load_seed'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activerecord-5.0.7.2/lib/active_record/tasks/database_tasks.rb:270:in `load_seed'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/activerecord-5.0.7.2/lib/active_record/railties/databases.rake:184:in `block (2 levels) in <top (required)>'
/Users/thomas.gray/.rvm/gems/ruby-2.6.1/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'

Tasks: TOP => db:seed
(See full trace by running task with --trace)

The release of version 2.0 of the Faker gem has broken the expectations of db/seeds.rb. The Faker::Date.between method now accepts keyword arguments instead of positional arguments. Faker::Date.between(25.years.ago, 18.years.ago) should be changed to Faker::Date.between(from: 25.years.ago, to: 18.years.ago) (as opposed to updating the Gemfile to use an older version, since it looks like the specs have already been updated to account for this).

Spec file has incorrect .between syntax due to update

"https://github.com/faker-ruby/faker/blob/master/doc/default/date.md" - Nicholas Stephenson

`require "rails_helper"

RSpec.describe "classroom_show_view" do
it "renders classroom information on the show view" do
view.lookup_context.prefixes = %w[students]
student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago))
#original... the spec syntax is wrong. .between is changed https://github.com/faker-ruby/faker/blob/master/doc/default/date.md
#student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
assign(:student, student)
render :template => "students/show.html.erb"
expect(rendered).to match /Bobby/
end

it "renders a students/student partial" do
view.lookup_context.prefixes = %w[students]
student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago))
#original... the spec syntax is wrong. .between is changed https://github.com/faker-ruby/faker/blob/master/doc/default/date.md
#student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
assign(:student, student)
render :template => "students/show.html.erb"
expect(rendered).to render_template(:partial => "students/_student")
end

it "displays the student information from the partial" do
#original... the spec syntax is wrong. .between is changed https://github.com/faker-ruby/faker/blob/master/doc/default/date.md
#student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
student = Student.create(name: 'Bobby', hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago))
assign(:student, student)
render :partial => "students/student.html.erb"
expect(rendered).to match /Bobby/
end
`
end

Missing keywords in seeds.rb

Missing keywords :from and :to in the 80.times do block

Currently:

80.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(25.years.ago, 18.years.ago))
end

Should be:

80.times do
Student.create(name: Faker::Name.name, hometown: Faker::Address.city, birthday: Faker::Date.between(from: 25.years.ago, to: 18.years.ago))
end

Problem with '/classrooms/show.html.erb'

When I did this lab, I discovered that there is a problem in the 'config/routes.rb' file. The line "resources :classrooms only: [:show]" was preventing one of the partials from loading properly in 'classrooms/show.html.erb'. This made one of the tests impassable until I removed "only: [:show]" from the routes file.

Rendering an Incorrect View

In spec/views/classroom_student_spec.rb line 8 and 16 renders:
render :template => "students/show.html.erb"
Should it rather be rendering the classrooms/show?:
render :template => "classrooms/show.html.erb" given that we are testing the classrooms view?

Spec test show view section

show view tests should be nested under classroom show view

I mistook show_view for student show view.

-Approved by beth urban

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.