This repository has been archived by the owner on Jun 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Filters on junior story model #16
Merged
berlintam
merged 22 commits into
rubycorns:master
from
TPei:filters_on_junior_story_model
Dec 11, 2016
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ef6471a
adds swap files to gitignore
TPei d755bc3
adds Filterable model to junior_stories_controller, allows for url fi…
TPei fce0c7a
merge master
TPei ea3ee19
can_publish does not exist anymore, apparently^^
TPei 27c156b
needs to exclude format param as well
TPei 5db541b
adds tests for paramter filtering
TPei daadee6
adds error handling to Filterable, adds specs for illegal filter params
TPei 55d087d
updates strings to use single quotes
TPei 5f37082
spec for a combination of legal and illegal filter params
TPei 16fbfe1
adds filter modal with all fields listed to search through
TPei 7541125
ommits a couple fields from filter list
TPei 429689a
like this layout better
TPei 6a6534f
ids should also not be filterable
TPei 8e51c28
instead of loading attributes from model, I provide a hash with demo …
TPei 022b352
form now points to actual action, submits fields, filtering works :)
TPei af43203
maked download as csv work with filtered stories
TPei 7a55b10
maked allowed_params more centralized and clean
TPei a94752c
revert unwanted vim indentation change
TPei ff6ba83
split params into allowed and required to remove duplication
TPei 0220014
hides filter reset button if nothing was filtered
TPei e9e4dbe
fix filename
TPei 84979cc
Merge branch 'master' into filters_on_junior_story_model
TPei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
/log/* | ||
!/log/.keep | ||
/tmp | ||
*.swp |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Filterable | ||
extend ActiveSupport::Concern | ||
|
||
module ClassMethods | ||
def filter(params) | ||
results = self.all | ||
params.each do |key, value| | ||
if results.column_names.include? key | ||
results = results.where(key => value) if value.present? | ||
end | ||
end | ||
results | ||
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'rails_helper' | ||
|
||
describe JuniorStoriesController do | ||
describe 'GET index' do | ||
context 'without filter params' do | ||
it 'assigns @junior_stories' do | ||
story = build :junior_story | ||
story.save | ||
get :index | ||
expect(assigns(:junior_stories)).to eq([story]) | ||
end | ||
|
||
it 'renders the index template' do | ||
get :index | ||
expect(response).to render_template('index') | ||
end | ||
|
||
it 'does not render index, but instead responds with csv' do | ||
get :index, format: 'csv' | ||
expect(response).not_to render_template('index') | ||
expect(response.content_type).to include 'application/csv' | ||
end | ||
end | ||
|
||
context 'with legal filter params' do | ||
it 'returns only the filter appropriate junior_story' do | ||
female_story = build :junior_story | ||
female_story.gender = 'female' | ||
female_story.save | ||
|
||
male_story = build :junior_story | ||
male_story.gender = 'male' | ||
male_story.save | ||
|
||
|
||
get :index, { 'gender' => 'female' } | ||
expect(assigns(:junior_stories)).to eq([female_story]) | ||
end | ||
|
||
it 'renders the index template' do | ||
get :index, { 'gender' => 'female' } | ||
get :index | ||
expect(response).to render_template('index') | ||
end | ||
|
||
it 'does not render index, but instead responds with csv' do | ||
get :index, { 'gender' => 'female', 'format' => 'csv' } | ||
expect(response).not_to render_template('index') | ||
expect(response.content_type).to include 'application/csv' | ||
end | ||
end | ||
|
||
context 'with illegal filter params' do | ||
it 'ignores illegal filter params but respects legal filter params' do | ||
female_story = build :junior_story | ||
female_story.gender = 'female' | ||
female_story.save | ||
|
||
male_story = build :junior_story | ||
male_story.gender = 'male' | ||
male_story.save | ||
|
||
|
||
get :index, { 'makes_no_sense' => 'random', 'gender' => 'female' } | ||
expect(assigns(:junior_stories)).to eq([female_story]) | ||
end | ||
|
||
it 'renders the index template' do | ||
get :index, { 'makes_no_sense' => 'random' } | ||
get :index | ||
expect(response).to render_template('index') | ||
end | ||
|
||
it 'does not render index, but instead responds with csv' do | ||
get :index, { 'makes_no_sense' => 'random', 'format' => 'csv' } | ||
expect(response).not_to render_template('index') | ||
expect(response.content_type).to include 'application/csv' | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that this belongs in the model, not the controller. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this really truly belongs anywhere^^ What makes you say it's better suited for the model? Thin controllers - fat models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup :)