Skip to content

Commit

Permalink
Added some specs for ListController.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveyken committed Jul 19, 2024
1 parent 13ef816 commit f3a3a2e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ListsController < ApplicationController
#----------------------------------------------------------------------------
def create
list_attr = list_params.to_h
list_attr[:user_id] = (current_user.id if params[:is_global].to_i.zero?)
list_attr["user_id"] = current_user.id if params["is_global"] != "1"

# Find any existing list with the same name (case insensitive)
if @list = List.where("lower(name) = ?", list_attr[:name].downcase).where(user_id: list_attr[:user_id]).first
Expand Down
41 changes: 41 additions & 0 deletions spec/controllers/lists_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,45 @@
require 'spec_helper'

describe ListsController do

Check notice

Code scanning / Rubocop

Keeps track of empty lines around block bodies. Note test

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body beginning.
before(:each) do
login
end

let(:list_url) { "/contacts?q%5Bs%5D%5B0%5D%5Bname%5D=&q%5Bs%5D%5B0%5D%5Bdir%5D=asc&q%5Bg%5D%5B0%5D%5Bm%5D=and&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Ba%5D%5B0%5D%5Bname%5D=first_name&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Bp%5D=cont&q%5Bg%5D%5B0%5D%5Bc%5D%5B0%5D%5Bv%5D%5B0%5D%5Bvalue%5D=test&distinct=1&page=1" }

describe "global list items" do
let(:list_name) { "Global list item"}

Check notice

Code scanning / Rubocop

Checks that block braces have or don't have surrounding space. For blocks taking parameters, checks that the left brace has or doesn't have trailing space. Note test

Layout/SpaceInsideBlockBraces: Space missing inside }.
let(:is_global) { "1" }
it "creating should be successful" do
post :create, params: { list: { name: list_name, url: list_url }, is_global: is_global }, xhr: true

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
expect(assigns(:list).persisted?).to eql(true)
expect(response).to render_template("lists/create")
end
it "updating should be successful" do
@list = List.create!(name: list_name, url: "/test")
post :create, params: { list: { name: list_name, url: list_url }, is_global: is_global }, xhr: true

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
expect(assigns(:list).persisted?).to eql(true)
expect(@list.reload.url).to eql(list_url)
expect(response).to render_template("lists/create")
end
it "delete list item" do
@list = List.create!(name: list_name, url: "/test")
delete :destroy, params: { id: @list.id }, xhr: true
expect { List.find(@list.id) }.to raise_error(ActiveRecord::RecordNotFound)
expect(response).to render_template("lists/destroy")
end
end

describe "personal list items" do
let(:list_name) { "Personal list item"}

Check notice

Code scanning / Rubocop

Checks that block braces have or don't have surrounding space. For blocks taking parameters, checks that the left brace has or doesn't have trailing space. Note test

Layout/SpaceInsideBlockBraces: Space missing inside }.
let(:is_global) { "0" }

it "creating should be successful" do
post :create, params: { list: { name: list_name, url: list_url }, is_global: is_global }, xhr: true

Check notice

Code scanning / Rubocop

Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. Note test

Style/HashSyntax: Omit the hash value.
expect(assigns(:list).persisted?).to eql(true)
expect(response).to render_template("lists/create")
end
end

Check notice

Code scanning / Rubocop

Keeps track of empty lines around block bodies. Note test

Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end.
end

0 comments on commit f3a3a2e

Please sign in to comment.