This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application < Rails::Application | |
# [...] other code... | |
if Rails.env.test? | |
config.middleware.insert_before 0, Rack::Cors do | |
allow do | |
origins '*' | |
resource '*', headers: :any, methods: %i[post] | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("User can", () => { | |
beforeEach(() => { | |
cy.deleteAndSeedDatabase(); | |
}); | |
afterEach(() => { | |
cy.deleteDatabase(); | |
}); | |
it("visits home page and see list of places", () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@albums = Album | |
.includes(:user) | |
.order("created_at DESC") | |
.where(category:"rock") | |
.where("minutes_length>55") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/album.rb | |
class Album < ApplicationRecord | |
# [...] other code | |
scope :rock , -> { where(category:"rock")} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/album.rb | |
class Album < ApplicationRecord | |
# [...] other code | |
def self.rock | |
where(category:"rock") | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/album.rb | |
class Album < ApplicationRecord | |
# [...] other code | |
scope :rock , -> { where(category:"rock")} | |
scope :long , -> {where("song_count">11)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/album.rb | |
class Album < ApplicationRecord | |
# [...] other code | |
scope :genre , -> (category) { where(category:category) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/controllers/albums_controller.rb | |
class AlbumsController < ActionController::Base | |
def index | |
@albums = Album.genre(params[:category]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ActiveRecord::Base | |
default_scope { where(published: true) } | |
end | |
Article.all # => SELECT * FROM articles WHERE published = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe Album, type: :model do | |
let!(:album1) { create(:album, category: 'rock') } | |
let!(:album2) { create(:album, category: 'rock') } | |
let!(:album3) { create(:album, category: 'pop') } | |
let!(:album4) { create(:album, category: 'jazz') } | |
describe '.genre' do | |
it 'includes albums with category specified' do | |
expect(Album.genre('rock')).to include(album1, album2) | |
end |