Skip to content

Commit

Permalink
add controller test for create
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Feb 23, 2024
1 parent 9e617f1 commit bda2677
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ group :test do
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

gem 'rails-controller-testing', '~> 1.0'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ GEM
activesupport (= 7.0.4.2)
bundler (>= 1.15.0)
railties (= 7.0.4.2)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
Expand Down Expand Up @@ -463,6 +467,7 @@ DEPENDENCIES
puma
rack
rails (= 7.0.4.2)
rails-controller-testing (~> 1.0)
rails-erd
rails-i18n
rb-readline
Expand Down
37 changes: 37 additions & 0 deletions spec/controllers/skills_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'rails_helper'

describe SkillsController do
describe 'SkillsController as user' do
before { load_pictures }

# before(:each) do
# allow_any_instance_of(SkillsController).to receive(:admin_flag?).and_return(true)
# end

let(:bob) { people(:bob) }

describe 'CRUD operaions' do
it 'index returns all skills ' do
get :index
skills = assigns(:skills)
expect(skills.sort).to eq skills().sort
expect(response).to render_template("index")
end

it 'post returns all skills ' do
title = 'new skill'
category_id = categories(:java).id
radar = "hold"
portfolio = "passiv"

post :create , params: { skill: { title: title, category_id: category_id, radar: radar, portfolio: portfolio} }
skill = assigns(:skill)
expect(skill.title).to eq title
expect(skill.category_id).to eq category_id
expect(skill.radar).to eq radar
expect(skill.portfolio).to eq portfolio
expect(response).to redirect_to(skills_path)
end
end
end
end
File renamed without changes.

0 comments on commit bda2677

Please sign in to comment.