Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Finish all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bthuilot committed Jul 19, 2019
1 parent b916c7b commit 0c5afe3
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ gem 'bootsnap', '>= 1.1.0', require: false

# Styles
gem 'jquery-rails'
gem 'material_icons'
gem 'bootstrap', '4.1.1'
gem 'material-sass', '4.1.1'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
1 change: 1 addition & 0 deletions app/models/system_page.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class SystemPage < ApplicationRecord
validates :name, uniqueness: true, presence: true, length: {maximum: 50}
end
7 changes: 0 additions & 7 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@
</li>
</ul>

<!-- TODO Fix styling for dropdown -->
<%= form_for :search, method: :get, html: {class: 'form-inline my-2 my-lg-0 navbar-search-select'}, url: '/search' do |form| %>
<%= form.select :category, Category.all.collect {|c| [c.name, c.id]}, {include_blank: 'All Categories'}, {class: 'custom-select navbar-dark select-no-border'} %>

<%= form.text_field :term, class: 'form-control mr-sm-2', placeholder: "Search" %>
<br>
<%= form.submit :search, class: 'btn btn-outline-success my-2 my-sm-0' %>
<% end %>
</div>
</nav>

29 changes: 26 additions & 3 deletions test/models/category_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
require 'test_helper'

class CategoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end

setup do
@category = Category.new({name: "Test Category", homepage: "# Hello World!!"})
end

test "Valid category" do
assert @category.valid?, "Category with unique name and a homepage"
end

test "Category missing name" do
@category.name = nil
refute @category.valid?, "Category with missing name"
assert_not_nil @category.errors[:name]
end

test "Category non unique name" do
@category.name = "Finance Category"
refute @category.valid?, "Category with duplicate name"
assert_not_nil @category.errors[:name]
end

test "Category name longer than 50 characters" do
@category.name = "-" * 51
refute @category.valid?, "Category with name longer than 50"
assert_not_nil @category.errors[:name]
end
end
27 changes: 24 additions & 3 deletions test/models/post_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
require 'test_helper'

class PostTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
setup do
@post = Post.new({title: "Test Post", contents: "# Hello World!!", category: categories(:dev_ops)})
end

test "Valid post" do
assert @post.valid?, "Post with title, category, and a contents"
end

test "Post is missing category" do
@post.category = nil
refute @post.valid?
end

test "Post missing title" do
@post.title = nil
refute @post.valid?, "Post with missing title"
assert_not_nil @post.errors[:title]
end

test "Post title longer than 50 characters" do
@post.title = "-" * 51
refute @post.valid?, "Post with title longer than 50"
assert_not_nil @post.errors[:title]
end
end
27 changes: 24 additions & 3 deletions test/models/system_page_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
require 'test_helper'

class SystemPageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
setup do
# Need to load in default system pages
# These are created in `seeds.rb` so
# This command loads it in before the tests run
Rails.application.load_seed
@system_page = SystemPage.new({name: "Test SystemPage", contents: "# Hello World!!"})
end

test "Valid system_page" do
assert @system_page.valid?, "SystemPage with unique name and a contents"
end

test "SystemPage missing name" do
@system_page.name = nil
refute @system_page.valid?, "SystemPage with missing name"
assert_not_nil @system_page.errors[:name]
end

test "SystemPage non unique name" do
@system_page.name = "Home"
refute @system_page.valid?, "SystemPage with duplicate name"
assert_not_nil @system_page.errors[:name]
end

end

0 comments on commit 0c5afe3

Please sign in to comment.