This repository has been archived by the owner on Nov 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished Controller test and Helper Tests
- Loading branch information
Showing
19 changed files
with
459 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
# Wiki | ||
# Pearl Wiki | ||
Open source wiki software powered by [rails](https://github.com/rails/rails) | ||
|
||
I started this project when I was looking for wiki software to use for a club I was a apart of and didn't like any of the options I found | ||
|
||
Thus spawned this! | ||
|
||
Checkout the live demo [here]() | ||
|
||
## Getting started | ||
*The wiki requires ruby versions >= 2.5.0* | ||
|
||
To install first clone the source using | ||
```bash | ||
$ git clone https://github.com/bthuilot/PearlWiki | ||
$ cd PearlWiki | ||
``` | ||
|
||
Once inside the cloned directory, run | ||
```bash | ||
# Install Dependecys | ||
$ gem install bundler && bundle install | ||
# Set up and seed database | ||
$ rake db:migrate | ||
$ rake db:seed | ||
# Start the server | ||
rails server | ||
``` | ||
|
||
## Code Status | ||
[](https://travis-ci.com/bthuilot/PearlWiki) | ||
|
||
## License | ||
Pearl Wiki is released under the [MIT License](). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
class SearchController < ApplicationController | ||
include MarkdownHelper | ||
include SearchHelper | ||
|
||
before_action :get_all_categories | ||
before_action :get_search_params | ||
before_action :set_textonly_renderer | ||
|
||
def search | ||
@posts = Post.search(@search_term, @search_category_id) | ||
@posts_length = @posts.length | ||
@max_page = (@posts_length / RESULTS_PER_PAGE) + 1 | ||
if @page > 1 | ||
start_result = (@page - 1) * RESULTS_PER_PAGE | ||
@posts = @posts[start_result...start_result + RESULTS_PER_PAGE] | ||
end | ||
@posts = get_search_results | ||
get_search_page | ||
end | ||
|
||
|
||
private | ||
|
||
RESULTS_PER_PAGE = 20 | ||
|
||
def get_all_categories | ||
@categories = Category.all | ||
end | ||
|
||
def get_search_params | ||
def get_search_results | ||
if params[:search] | ||
@search_term = params[:search][:search_term] | ||
@search_category_id = /\A\d+\z/.match(params[:search][:search_category]) ? params[:search][:search_category].to_i : nil | ||
@page = params[:page].to_i || 1 | ||
search_term = params[:search][:term] | ||
search_category_id = /\A\d+\z/.match(params[:search][:category]) ? params[:search][:category].to_i : nil | ||
end | ||
Post.search(search_term, search_category_id) | ||
end | ||
|
||
def get_search_page | ||
@page = params[:page] ? [params[:page].to_i, get_max_page].min : 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
require 'redcarpet/render_strip' | ||
module MarkdownHelper | ||
def set_renderer | ||
@markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) | ||
def markdown_renderer | ||
Redcarpet::Markdown.new(Redcarpet::Render::HTML) | ||
end | ||
|
||
def set_textonly_renderer | ||
@textonly = Redcarpet::Markdown.new(Redcarpet::Render::StripDown) | ||
def textonly_renderer | ||
Redcarpet::Markdown.new(Redcarpet::Render::StripDown) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
require 'test_helper' | ||
|
||
class SearchControllerTest < ActionDispatch::IntegrationTest | ||
test "Should get search page" do | ||
get search_url | ||
assert_response :success | ||
assert_equal 32, @controller.instance_variable_get(:@posts).length | ||
assert_select ".list-group-item", {count: 20} | ||
assert_equal 1, @controller.instance_variable_get(:@page) | ||
assert_select ".all-results-button", "All Results (32)" | ||
assert_select ".next-page-button", "keyboard_arrow_right" | ||
assert_select ".prev-page-button", {count: 0} | ||
assert_select ".page-buttons", {count: 2} | ||
assert_select ".list-group-item", {count: 20} | ||
assert_select ".page-buttons.active", {count: 1} | ||
end | ||
|
||
test "Should get all results" do | ||
get search_url, params: {page: -1} | ||
assert_response :success | ||
assert_equal -1, @controller.instance_variable_get(:@page) | ||
assert_select ".prev-page-button", {count: 0} | ||
assert_select ".next-page-button", {count: 0} | ||
assert_select ".page-buttons.active", {count: 0} | ||
assert_select ".list-group-item", {count: 32} | ||
assert_select ".all-results-button.active", "All Results (32)" | ||
end | ||
|
||
test "Should get page 2" do | ||
get search_url, params: {page: 2} | ||
assert_response :success | ||
assert_equal 2, @controller.instance_variable_get(:@page) | ||
assert_select ".page-buttons.active", {value: 2} | ||
assert_select ".prev-page-button", {count: 1} | ||
assert_select ".next-page-button", {count: 0} | ||
assert_select ".list-group-item", {count: 12} | ||
end | ||
|
||
test "Should only get posts in dev ops category" do | ||
get search_url, params: {search: {category: categories(:dev_ops).id}} | ||
assert_response :success | ||
assert_equal 1, @controller.instance_variable_get(:@page) | ||
assert_select ".page-buttons.active", {value: 1} | ||
assert_select ".prev-page-button", {count: 0} | ||
assert_select ".next-page-button", {count: 0} | ||
assert_select ".list-group-item", {count: 20} | ||
assert_select ".list-group-item" do | ||
assert_select "div small", "Category: Developer Operations Category" | ||
end | ||
end | ||
|
||
test "Should only get posts with 0 in title" do | ||
get search_url, params: {search: {term: "0"}} | ||
assert_response :success | ||
assert_equal 1, @controller.instance_variable_get(:@page) | ||
assert_select ".page-buttons.active", {value: 1} | ||
assert_select ".prev-page-button", {count: 0} | ||
assert_select ".next-page-button", {count: 0} | ||
assert_select ".list-group-item", {count: 3} | ||
assert_select ".list-group-item" do | ||
assert_select "h5", /.+0/ | ||
end | ||
end | ||
|
||
test "Should only get posts with 0 in title and in dev ops category" do | ||
get search_url, params: {search: {category: categories(:dev_ops).id, term: "0"}} | ||
assert_response :success | ||
assert_equal 1, @controller.instance_variable_get(:@page) | ||
assert_select ".page-buttons.active", {value: 1} | ||
assert_select ".prev-page-button", {count: 0} | ||
assert_select ".next-page-button", {count: 0} | ||
assert_select ".list-group-item", {count: 2} | ||
assert_select ".list-group-item" do | ||
assert_select "h5", /.+0/ | ||
end | ||
assert_select ".list-group-item" do | ||
assert_select "div small", "Category: Developer Operations Category" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.