Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
add new specs
Browse files Browse the repository at this point in the history
  • Loading branch information
deniznida committed Jun 25, 2015
1 parent db0ed53 commit 196a21c
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .learn
Expand Up @@ -4,4 +4,4 @@ tags:
- activerecord
languages:
- ruby
resources: 2
resources: 2
12 changes: 6 additions & 6 deletions README.md
@@ -1,11 +1,11 @@
---
tags: sinatra, orm, activerecord
languages: ruby
resources: 2
---

# Sinatra Playlister

##Objectives

1. Solidify your ActiveRecord understanding
2. Build views for your models


### Overview

In the theme of moving from simple command line application to static website to dynamic web app, it's time to move Playlister to the interwebs using Sinatra. In this lab, you'll be:
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -2,4 +2,8 @@ class ApplicationController < Sinatra::Base
register Sinatra::ActiveRecordExtension
set :session_secret, "my_application_secret"
set :views, Proc.new { File.join(root, "../views/") }

get '/' do
erb :index
end
end
3 changes: 2 additions & 1 deletion db/seeds.rb
@@ -1 +1,2 @@
# Add seed data here. Seed your database with `rake db:seed`
# Add seed data here. Seed your database with `rake db:seed`

File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions spec/models/01_song_spec.rb
@@ -0,0 +1,43 @@
require 'spec_helper'

describe "Song" do
let!(:artist) { Artist.create(:name => "Taylor Swift") }

let!(:song) { Song.create(:name => "Blank Space", :artist => artist) }

let!(:pop) { Genre.create(:name => "Pop") }
let!(:funk) { Genre.create(:name => "Funk") }

let!(:song_genres_pop) { SongGenre.create(:song_id => song.id, :genre_id => pop.id) }
let!(:song_genres_funk) { SongGenre.create(:song_id => song.id, :genre_id => funk.id) }

it "can initialize a song" do
expect(Song.new).to be_an_instance_of(Song)
end

it "can have a name" do
expect(song.name).to eq("Blank Space")
end

it "can have many genres" do
expect(SongGenre.count).to eq(2)
end

it "has an artist" do
expect(song.artist).to eq(artist)
end

it "can slugify it's name" do
song.slug

expect(song.slug).to eq("blank-space")
end

describe "Class methods" do
it "given the slug can find a song" do
Song.find_by_slug(song.slug)

expect((Song.find_by_slug(song.slug)).name).to eq("Blank Space")
end
end
end
47 changes: 47 additions & 0 deletions spec/models/02_genre_spec.rb
@@ -0,0 +1,47 @@
require 'spec_helper'

describe "Genre" do
let(:genre) { Genre.create(:name => "Pop") }

let!(:taylor_swift) { Artist.create(:name => "Taylor Swift") }
let!(:mark_ronson) { Artist.create(:name => "Mark Ronson") }

let!(:blank_space) { Song.create(:name => "Blank Space", :artist => taylor_swift) }
let!(:uptown_funk) { Song.create(:name => "Uptown Funk!", :artist => mark_ronson) }

let!(:blank_pop) { SongGenre.create(:song_id => blank_space.id, :genre_id => genre.id) }
let!(:uptown_pop) { SongGenre.create(:song_id => uptown_funk.id, :genre_id => genre.id) }


it "can initialize a genre" do
expect(Genre.new).to be_an_instance_of(Genre)
end

it "has a name" do
expect(genre.name).to eq("Pop")
end

it "has many songs" do
expect(genre.songs.count).to eq(2)
end

it "has many artists" do
expect(genre.artists.count).to eq(2)
end

it "can slugify it's name" do
genre = Genre.create(:name => "Alternative Rock")
genre.slug

expect(genre.slug).to eq("alternative-rock")
end

describe "Class methods" do
it "given the slug can find a genre" do
genre = Genre.create(:name => "Alternative Rock")
Genre.find_by_slug(genre.slug)

expect((Genre.find_by_slug(genre.slug)).name).to eq("Alternative Rock")
end
end
end
46 changes: 46 additions & 0 deletions spec/models/03_artist_spec.rb
@@ -0,0 +1,46 @@
require 'spec_helper'

describe "Artist" do
let(:artist) { Artist.create(:name => "Taylor Swift") }

let!(:blank_space) { Song.create(:name => "Blank Space", :artist => artist) }
let!(:shake_it_off) { Song.create(:name => "Shake It Off", :artist => artist) }

let!(:pop) { Genre.create(:name => "Pop") }
let!(:funk) { Genre.create(:name => "Funk") }

let!(:blank_pop) { SongGenre.create(:song_id => blank_space.id, :genre_id => pop.id) }
let!(:blank_funk) { SongGenre.create(:song_id => blank_space.id, :genre_id => funk.id) }


it "can be initialized" do
expect(artist).to be_an_instance_of(Artist)
end

it "can have a name" do
expect(artist.name).to eq("Taylor Swift")
end

it "has many songs" do
expect(artist.songs.count).to eq(2)
end

it "can have many genres" do
expect(artist.genres.count).to eq(2)
end

it "can slugify it's name" do
artist.slug

expect(artist.slug).to eq("taylor-swift")
end

describe "Class methods" do
it "given the slug can find a Artist" do
Artist.find_by_slug(artist.slug)

expect((Artist.find_by_slug(artist.slug)).name).to eq("Taylor Swift")
end
end

end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -9,6 +9,8 @@
raise 'Migrations are pending. Run `rake db:migrate SINATRA_ENV=test` to resolve the issue.'
end

ActiveRecord::Base.logger = nil

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
Expand Down

0 comments on commit 196a21c

Please sign in to comment.