Commit 0cf8c7e2 authored by Huynh Nguyen V's avatar Huynh Nguyen V
Browse files

fix category create

No related merge requests found
Showing with 25 additions and 3 deletions
+25 -3
......@@ -15,6 +15,7 @@ gem "tux"
gem 'sinatra-formhelpers-ng'
gem 'faker'
gem 'will_paginate', '~> 3.0'
gem 'nokogiri', '~> 1.6', '>= 1.6.8'
group :test do
gem 'rspec'
......
......@@ -6,6 +6,24 @@ RSpec.describe "categories", type: :controller do
CategoryController.new
end
context "index categories" do
it 'should return success response' do
get "/categories"
expect(last_response.status).to eq 200
end
it 'should to list count page one' do
create_list :category, 2
get "/categories"
doc = Nokogiri::HTML(last_response.body)
array_category = []
doc.css('.name').each do |l|
array_category << l.content
end
expect(array_category.length).to eq 2
end
end
context "create categories" do
let(:params) do
{ category: {name: "name category"}}
......@@ -21,5 +39,6 @@ RSpec.describe "categories", type: :controller do
category_first = Category.first
expect(category_first.name).to eq "name category"
end
end
end
end
\ No newline at end of file
FactoryBot.define do
factory :category do |f|
f.name { Faker::Name.name }
factory :category do
sequence(:name) { |n| Faker::Name.name }
end
end
......@@ -4,6 +4,8 @@ require "rack/test"
require './config/environment'
require 'factory_bot'
require 'database_cleaner'
require 'nokogiri'
require 'open-uri'
DatabaseCleaner.strategy = :truncation
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment