Code Monkey home page Code Monkey logo

rails-cru-form_for-lab's Introduction

CRU with form_for Lab

Objectives

  1. Build RESTful actions for index, show, new, create, edit, update
  2. Use form_for for all forms (no need to share forms or partials)
  3. Correctly redirect when needed
  4. Interlink between pages using route helpers

Instructions

You've been tasked with building a Rails app called Beats by Rails, the app will need to have three separate models:

  • Songs

  • Artists

  • Genres

The data relationship will look something like this:

  • A song belongs to an artist

  • A song belongs to a genre

  • A genre has many songs

  • An artist has many songs

The tests are in the spec/features directory for each model. You will need to build in the ability to create, update, and show for each model. And for the song show page you need to have it display each of the song's genre and artist, and link to the respective genre and artist show pages.

The database tables should look like this (note each column type):

table "artists"
  string   "name"
  text     "bio"

table "genres"
  string   "name"

table "songs"
  string   "name"
  integer  "artist_id"
  integer  "genre_id"

Key notes to remember

  • You will need to use strong params

  • Don't worry about integrating drop down form elements for the genre and artist selections on the song form pages yet, simply enter in the ID in for each element

  • You can use the resource, model, migration, and controller generators, but do not use the scaffold generator Top Tip: Remember to use the --no-test-framework flag when generating models and controllers to avoid generating unnecessary testing frameworks!

rails-cru-form_for-lab's People

Watchers

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

rails-cru-form_for-lab's Issues

Song's Edit Form Test Typo

This typo persists (I see an issue was raised/closed about it before).
Two specs titles refer to the new form for Songs.
Please change the second one to Edit, to avoid confusion.
Thanks in advance.

Update to wording for genre_spec.rb that causes student confusing

Submitted PR #11 to update wording to remove student confusion for why the test is failing.

The final test in genre_spec.rb uses the same wording as the previous test. The test for the new form and edit form have the same wording.

it 'shows a new form that submits content and redirects and prints out params'

This is a causing confusion for students as they think something is wrong with their new genre form when the issue is actually their edit genre form.

Updated the wording for the edit form test to instead read:

it 'shows an edit form that submits content and redirects and prints out params'

Failing Test

After checking with tech support that my routes were set up correctly, this test fails and can't be figured out. artists_controller_spec

describe "GET #update" do it "returns http success" do get :update expect(response).to have_http_status(:success) end end

test for song index page

songs index page is expected to contain genre and artist information. only way to satisfy this expectation is for each song in index list to display artist and genres of that song. this is more appropriate for the show page, not the index page.

Update wording on Song spec to avoid confusion

This issue is similar to the existing one raised for the genre spec last year. The following capybara tests (within the Song spec) have identical descriptions, yet are testing two separate forms (new vs edit) in two separate view files:

 it 'shows a new form that submits content and redirects and prints out params' do
    visit new_song_path

    fill_in 'song[name]', with: "My song name"
    fill_in 'song[artist_id]', with: @artist.id
    fill_in 'song[genre_id]', with: @genre.id

    click_on "Create Song"

    expect(page).to have_content("My song name")
  end

  it 'shows a new form that submits content and redirects and prints out params' do
    @song = Song.create(name: "My Song", artist_id: @artist.id, genre_id: @genre.id)

    visit edit_song_path(@song)

    fill_in 'song[name]', with: "My edit"
    fill_in 'song[artist_id]', with: @artist.id
    fill_in 'song[genre_id]', with: @genre.id

    click_on "Update Song"

    expect(page).to have_content("My edit")
  end

Suggestion is to change the it block on the second test to indicate that the test is checking the Edit Song view/form.

Testing specs do not allow for artist/genre selections

The testing specs require the use of text fields (as far as i could tell) to associate a song with a song and artist on the song's show/edit pages. the user would have to know the ID of the genre and artist they would like to associate the song to in order for them to be able to create a song. this is not user friendly and also makes very little sense, which makes getting all the tests to pass a confusing mess.

the testing specs should allow for a dropdown or checkbox selection for artist/genre menus. this way it makes sense to both users and developers.

secrets.yml

config/secrets.yml was added to .gitignore so students don't get it when they fork and clone this lab. Rails needs this file with its contents in order to run and app. Either remove this file from .gitignore and add instructions for students to create and populate this file.

Post show page code from readme seemed to reference an object that didn't exist

This very well could have been on my end, but I had issues with the below code on my post show page. The test data seemed to be a post without a category, so any attempts to call post.category caused a no method on nil class error.

Again, very well could have been an issue with how I went about the lab on my end though.

Thanks!

<%# app/views/posts/show.html.erb %>

<%= @post.title %>

Category: <%= link_to @post.category, category_path(@post.category) %>

<%= @post.description %>

Generators generate bad controller tests

Readme should mention to use --no-test-framework when generating models and controllers. Otherwise model tests will be pending but controller tests will be generated that dont make sense with this app. @PeterBell

Please revise this lab

Tests are looking for an integer for artist_id and genre_id, but you are given a text box. Please make this clear that it's supposed to be a number!

tests needs revision

spec for the songs form

shows a new form that submits content and redirects and prints out params
shows a new form that submits content and redirects and prints out params

should be

shows a new form that submits content and redirects and prints out params
shows an edit form that submits content and redirects and prints out params

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.