Giter Site home page Giter Site logo

namespaced-routes-lab's Introduction

Namespaced Routes Lab

Objectives

  1. Organize controllers using a module.
  2. Use namespaced routes.

Overview

We're going to add some administrative functions to our song library. Using what we learned about namespaced routes and module scope, we'll organize our controllers and routes under an admin namespace to keep them separate from the regular user functions.

Instructions

The base application has been provided with tests. Make sure to run rake db:seed to set up seed data. Tests can be run with rspec.

Note: Since we're building new features on an existing project that already has tests, part of the job is to make sure the tests that already pass at the beginning still pass when you're done!

  1. Create a migration and a model for a Preference class that will store preferences for the app. In the migration, define boolean fields for:
    • allow_create_songs: Allows for creation of new songs. Used to control the ability to add new songs to the system.
    • allow_create_artists: Allows for creation of new artists. Used to control the ability to add new artists to the system.
    • Note: There will only be 1 instance of Preference, not a preference associated with each artist/song. After creating the model, run rake preferences:load so that your code will work in the browser. This will run the Rake task defined in the lib/tasks/preferences.rake file and save one Preference instance to the database.
  2. Create a PreferencesController, routes, and views. Do this under an Admin module to separate it from the standard user functionality.
  3. Update the songs#new and artists#new actions to check that creating new songs or artists is enabled using the Preference class, and redirect to /songs and /artists, respectively, if that preference is disabled. If the preference is enabled, show the new view instead.
    • Hint: Remember, there will only be one instance of the Preference class saved to the database. When determining if creating songs or artists is enabled, you'll need to find the first instance of the Preference class, and use that instance along with some conditional logic to determine whether to redirect or display the view.
  4. Make sure tests pass.

namespaced-routes-lab's People

Watchers

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

namespaced-routes-lab's Issues

Test don't run out of order.

Running a single feature spec file or individual specs causes the error "Uninitialized Constant Artist". This has something to do with how the database cleaning is being handled. The specs should be able to run independently by file and by spec.

Missing RSpec test

There's currently no RSpec test for 3. Update the artists and songs index pages to order by name according to each preference.

Line 43 in Songs_controller_spec

In this spec file i commented out line 43 because, according to the tech coach, the code is doing what it's supposed to be doing, but the test is still not passing.

Failures:

  1. SongsController GET show with artist redirects to artists songs when artist song not found
    Failure/Error: expect(controller).to set_flash[:alert]

    NameError:
    undefined local variable or method `set_flash' for #RSpec::ExampleGroups::SongsController::GETShowWithArtist:0x007fab86807850

    ./spec/controllers/songs_controller_spec.rb:43:in `block (3 levels) in '

tests passed w/o correct code

my tests passed and I checked the solutions after.. and there's a bunch of code in the controllers that I did have to put in for the tests to pass .. just FYI

Instructions and tests unclear about how Preferences are associated with Artists and Songs

Let me start by saying that this is essentially the same issue that was raised here: learn-co-students/namespaced-routes-lab-v-000#1027

I'm currently stuck on this lab because I don't understand how Preferences are supposed to affect Songs and Artists.

According to the README and tests, each Preference has two attributes: allow_create_artists and allow_create_songs, both of which can be set to true or false. The README also says that "...There will only be 1 instance of Preference, not a preference associated with each artist/song."

The tests also specify that there needs to be an index file for Preferences. Additionally, the artists_controller_spec and songs_controller_spec files have these lines of code:

#artists_controller_spec.rb
describe "GET new" do
    it "redirects when access is turned off" do
      p = Preference.create(allow_create_artists: false)
      get :new
      expect(response).to redirect_to artists_path
    end
  end
#songs_controller_spec.rb
describe "GET new" do
    it "redirects when access is turned off" do
      p = Preference.create(allow_create_songs: false)
      get :new
      expect(response).to redirect_to songs_path
    end
  end

So, all that said, here's what I'm unclear on: How are the ArtistsController and SongsController supposed to know that they need to redirect from their new actions when a new Preference has been created?

#7 on README is wrong?

Update the artists and songs index pages to order by name according to each preference.

From the directions on the README it seems like you want us to update the Artist and Song index views. However, the tests did not test for views and the solution did not make changes to the view pages so this direction is confusing.

Lab Instructions Unclear

I feel like I cheated the solution to get the tests to pass. So I looked at the solution to compare my code and I didn't really see any solution/change to original code. I am very confused as to what exactly I should be learning from this lab.

Errors when running rake db:seed

After opening the lab and running rake db:seed i got the following errors:

rake aborted!
LoadError: cannot load such file -- active_storage/engine
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:80:in `register'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:36:in `rescue in require'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/bootsnap-1.4.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:25:in `require'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/activesupport-5.0.7.1/lib/active_support/dependencies.rb:293:in `block in require'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/activesupport-5.0.7.1/lib/active_support/dependencies.rb:259:in `load_dependency'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/activesupport-5.0.7.1/lib/active_support/dependencies.rb:293:in `require'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/config/application.rb:8:in `<top (required)>'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/Rakefile:4:in `require'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/Rakefile:4:in `<top (required)>'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>' 

So I tried commenting out #require 'active_storage/engine' in config/application.rb but then I get the error:

rake aborted!
NoMethodError: undefined method `load_defaults' for #<Rails::Application::Configuration:0x00007fb26ed473f8>
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/railties-5.0.7.1/lib/rails/railtie/configuration.rb:95:in `method_missing'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/config/application.rb:23:in `<class:Application>'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/config/application.rb:21:in `<module:DisplayingAssociationsRailsLab>'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/config/application.rb:20:in `<top (required)>'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/Rakefile:4:in `require'
/Users/heathermiller/flatiron/namespaced-routes-lab-v-000/Rakefile:4:in `<top (required)>'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `eval'
/Users/heathermiller/.rvm/gems/ruby-2.5.3/bin/ruby_executable_hooks:24:in `<main>'
(See full trace by running task with --trace

After this, every google rabbit hole I start going down just leads me to more errors

Solution already supplied.

I don't know if this was intentional or not but the majority of the solution for this lab was already completed. The only code I had to write in order to pass all of the tests was only what was declared in Number 4 of the instructions:

  1. Update the artists#index action to order by name with artist_sort_order and the songs#index action to order songs by title with song_sort_order. Make sure to check that the value exists and set it to the default if it doesn't.

Lab unclear

I already made a comment on someone else's issue here, but I wanted to create an individual issue because I am not sure if the curriculum team is alerted based on new issues raised, or new comments. It's pretty clear by the number of issues students have raised about this lab that the curriculum people need to be alerted.

The instructions are terribly unclear. It's frustrating because I really want to practice my skills on the topic.

FYI : Readme instructions and forked lab tests are not 100% consistent

Situation : After reading the readme, I then follow the tests and only refer back to the readme if I get stuck and am searching for further information.

Issue? : I reached the end of the "failed" tests and noticed (after checking because I briefly thought I was going crazy) that the "7) Update the artists and songs index pages to order by name according to each preference" instruction did not have a test.

Directions Unclear

It was pretty unclear that there was only going to be 1 instance of Preference rather than a preference associated w each artist/song with a has_many belongs_to relationship.

`rake preferences:load` command unclear

Hi. The README says that after we create the Preference model, we have to "run rake preferences:load so that your code will work in the browser".

However, after creating that model and migrations, migrating my database, and running that Rake command, I got this error in my console:

rake aborted!
Don't know how to build task 'preferences:load' (See the list of available tasks with `rake --tasks`)

So, here's my question: What is rake preferences:load supposed to do?

---Sdcrouse

Clone error

this cloned lab has almost all of the steps already finished for us.

No specs for requirement 7

Hello! I didn't see any specs for the 7th requirement (regarding the ordering of artists and songs according to a preference). Also, some explanation about the relationship between preferences and the other models would be useful . . .

I think a test may be missing to check for ASC or DESC order.

#6 On this lab's ReadMe states:

Create a PreferencesController, routes, and views to manage the preferences. Do this under an Admin module to separate it from the standard user functionality. The artists and songs index pages should order by name according to each preference.

However, there are no requirements that we put anything in the index pages to order the songs/artist by name. I may be misinterpreting what #6 is saying, but I assumed there would be some sort of test to check Preference.song_sort_order and Preference.artist_sort_order.

Varying README files

The README on the Learn.co website is different from the README file in the Github repo. It might be confusing because the former README doesn't mention SettingsController and AccessController.

gem dependency issues, unable to run specs

When you first try to run the tests, you get this error:

An error occurred while loading ./spec/controllers/admin/preferences_controller_spec.rb.
Failure/Error: require File.expand_path('../../config/environment', FILE)

LoadError:
cannot load such file -- active_storage/engine

My students let me know that using the latest version of rails instead of 5.0.7.1, and adding gem 'listen' to the gemfile will fix this issue, but I'm not sure why that works exactly, or if that's a solution that will work in perpetuity.

#staff

starting state

@scottcreynolds hey scott, i missed this in my review but if you run rspec on the clean master branch you end up passing a lot of the tests. i'm not sure if some of the tests are old from the last lab or if there's not supposed to be any starter code. figured it'd be a lot easier for you to take a look rather than me guessing.

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.