From bda26775981816fb3806f9c344f06997e52caf9b Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 23 Feb 2024 11:38:16 +0100 Subject: [PATCH] add controller test for create --- Gemfile | 2 + Gemfile.lock | 5 +++ spec/controllers/skills_controller_spec.rb | 37 +++++++++++++++++++ ...skill_form_spec.rb => skills_form_spec.rb} | 0 4 files changed, 44 insertions(+) create mode 100644 spec/controllers/skills_controller_spec.rb rename spec/features/{skill_form_spec.rb => skills_form_spec.rb} (100%) diff --git a/Gemfile b/Gemfile index 5a6db755c..d6be3ffa0 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 6a9b42351..82f0b7e6a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -463,6 +467,7 @@ DEPENDENCIES puma rack rails (= 7.0.4.2) + rails-controller-testing (~> 1.0) rails-erd rails-i18n rb-readline diff --git a/spec/controllers/skills_controller_spec.rb b/spec/controllers/skills_controller_spec.rb new file mode 100644 index 000000000..07b8f214c --- /dev/null +++ b/spec/controllers/skills_controller_spec.rb @@ -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 diff --git a/spec/features/skill_form_spec.rb b/spec/features/skills_form_spec.rb similarity index 100% rename from spec/features/skill_form_spec.rb rename to spec/features/skills_form_spec.rb