-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Journalist can assign an article to a category #26
Open
holgertidemand
wants to merge
16
commits into
CraftAcademy:develop
Choose a base branch
from
holgertidemand:categories
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
37f2beb
fixed merge conflicts with upstream
holgertidemand 0895310
started with feature test
holgertidemand f786baa
adds ability to add and category to an article
holgertidemand 80b55c8
working on adding more then one category to an article
holgertidemand 482a588
merge with upsrteam
holgertidemand cc6c2f6
refactored home controller for better readability
holgertidemand 3463f69
merge with upstream
holgertidemand 4054101
refactor add categories to article method
holgertidemand 39c6547
cleaned up in unit test for category
holgertidemand 0d90de1
recatored new article form to not allow multiple category choose
holgertidemand 5bd8398
adds category controller
holgertidemand ef8065b
removes index method from article controller
holgertidemand 4f431e3
refactored requested changes
holgertidemand da05695
refactor old test to pass with new validation rules
holgertidemand a1c6e50
removed changes nor related to this PR
holgertidemand 1b9cf58
refactors feature test for category view page
holgertidemand 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
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,5 @@ | ||
class CategoriesController < ApplicationController | ||
def show | ||
@category = Category.find_by(id: params[:id]) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,13 @@ class HomeController < ApplicationController | |
before_action :get_coordinates, only: [:index] | ||
|
||
def index | ||
if [email protected]? | ||
user = create_guest_user | ||
location = (current_user ? current_user.address : user.address) | ||
@local_articles = Article.near(location, 20) | ||
@articles = Article.all | ||
else | ||
@articles = Article.all | ||
end | ||
if [email protected]? | ||
user = create_guest_user | ||
location = (current_user ? current_user.address : user.address) | ||
@local_articles = Article.near(location, 20) | ||
end | ||
@articles = Article.all | ||
@categories = Category.all | ||
end | ||
|
||
def get_location | ||
|
@@ -44,5 +43,4 @@ def update_user_location | |
current_user.save | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
class Article < ApplicationRecord | ||
after_validation :reverse_geocode # auto-fetch address | ||
reverse_geocoded_by :latitude, :longitude | ||
validates :title, :content, presence: true | ||
|
||
validates :title, :content, :categories, presence: true | ||
has_many :comments, dependent: :destroy | ||
has_and_belongs_to_many :categories | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Category < ApplicationRecord | ||
has_and_belongs_to_many :articles | ||
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,6 @@ | ||
%h1= @category.name | ||
|
||
- if @category.articles | ||
- @category.articles.each do |article| | ||
%h3= article.title | ||
%p= article.content |
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,9 @@ | ||
class CreateCategories < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :categories do |t| | ||
t.string :name | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
db/migrate/20180322210143_create_join_table_article_category.rb
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,8 @@ | ||
class CreateJoinTableArticleCategory < ActiveRecord::Migration[5.2] | ||
def change | ||
create_join_table :articles, :categories do |t| | ||
t.index [:article_id, :category_id] | ||
t.index [:category_id, :article_id] | ||
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,26 @@ | ||
Given("the following categories exists") do |table| | ||
table.hashes.each do |category| | ||
create(:category, category) | ||
end | ||
end | ||
|
||
Given("the following article are assigned to categories") do |table| | ||
table.hashes.each do |article| | ||
category = Category.find_by(name: article[:category]) | ||
article = Article.find_by(title: article[:title]) | ||
article.categories.push category | ||
end | ||
end | ||
|
||
Given("I am on the Create Article page") do | ||
visit new_article_path | ||
end | ||
|
||
Then("I select {string} from {string}") do |category, select_box| | ||
select category, from: select_box | ||
end | ||
|
||
Then("I should be on the {string} page") do |category_name| | ||
category = Category.find_by(name: category_name) | ||
expect(page.current_path).to eq category_path(category) | ||
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
Empty file.
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
Empty file.
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 @@ | ||
Given("the following user exists") do |table| | ||
table.hashes.each do |user| | ||
FactoryBot.create(:user, user) | ||
create(:user, user) | ||
end | ||
end | ||
|
||
Given("I am logged in as {string}") do |email| | ||
user = User.find_by(email: email) | ||
login_as(user, scope: :user) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Given("following user exist") do |table| | ||
table.hashes.each do |user| | ||
FactoryBot.create(:user, user) | ||
create(:user, user) | ||
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Feature: Better orginized websitet with categories | ||
As a subscriber | ||
In order to be able to find content of interest | ||
I would like to be able to filter articles by category | ||
|
||
Background: | ||
Given the following user exists | ||
| email | password | | ||
| [email protected] | OsloOslo123 | | ||
|
||
And the following categories exists | ||
| name | | ||
| Fashion | | ||
| Tech | | ||
|
||
And I am logged in as "[email protected]" | ||
|
||
Scenario: User creates a new article and asign it to a category | ||
Given I am on the Create Article page | ||
Then I fill in "Title" with "A Whole New Article" | ||
And I fill in "Content" with "A new fantastic Article" | ||
And I select "Tech" from "categories" | ||
When I click "Create Article" button | ||
Then I should be on "A Whole New Article" page | ||
And I should see "A Whole New Article" | ||
And I should see "A new fantastic Article" | ||
And I should see "Tech" |
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,34 @@ | ||
Feature: User should be able to visit a category page | ||
As a subscriber | ||
In order to be able to find content of interest | ||
I would like to be able to filter articles by category | ||
|
||
Background: | ||
Given the following categories exists | ||
| name | | ||
| Fashion | | ||
| Tech | | ||
|
||
And the following article exists | ||
| title | content | | ||
| A Whole New World | A new fantastic point of view | | ||
| A Whole New Article | A new fantastic article | | ||
|
||
And the following article are assigned to categories | ||
| title | category | | ||
| A Whole New World | Fashion | | ||
| A Whole New Article | Tech | | ||
|
||
Scenario: User visits the Fashion page | ||
Given I visit the Homepage | ||
When I click on the "Fashion" button | ||
Then I should be on the "Fashion" page | ||
And I should see "A Whole New World" | ||
And I should see "A new fantastic point of view" | ||
|
||
Scenario: User visits the Tech page | ||
Given I visit the Homepage | ||
When I click on the "Tech" button | ||
Then I should be on the "Tech" page | ||
And I should see "A Whole New Article" | ||
And I should see "A new fantastic article" |
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,5 @@ | ||
FactoryBot.define do | ||
factory :category do | ||
name "MyString" | ||
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.
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.
Why not do this in the step definition where you create articles?
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.
This made more since to us. didn't know if that would mess up all the other test that are using that step so we decided to make a new one.