-
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
base: develop
Are you sure you want to change the base?
Changes from 5 commits
37f2beb
0895310
f786baa
80b55c8
482a588
cc6c2f6
3463f69
4054101
39c6547
0d90de1
5bd8398
ef8065b
4f431e3
da05695
a1c6e50
1b9cf58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Article < ApplicationRecord | ||
validates :title, :content, presence: true | ||
has_many :comments, dependent: :destroy | ||
has_and_belongs_to_many :categories | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Category < ApplicationRecord | ||
has_and_belongs_to_many :artilces | ||
end |
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Given("the following categories exists") do |table| | ||
table.hashes.each do |category| | ||
create(:category, 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sense that you are mixing styles. Most of the step definitions omit the parathesis, here you have them. Stick to one style, please. |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 following article exists | ||
| title | content | | ||
| A Whole New World | A new fantastic point of view | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you have this background step here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't sure how we would make it write the test in the beginning. Will remove it! |
||
And the following user exists | ||
| email | password | | ||
| [email protected] | OsloOslo123 | | ||
And the following categories exists | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please separate steps in the background with an empty line. |
||
| 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 "Fashion" from "categories" | ||
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 "Fashion" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :category do | ||
name "MyString" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Category, type: :model do | ||
describe "Factory" do | ||
it "should have a valid factory" do | ||
article = create(:category) | ||
expect(create(:category)).to be_valid | ||
end | ||
end | ||
|
||
describe "Assosiation" do | ||
it {is_expected.to have_and_belong_to_many :articles} | ||
end | ||
|
||
describe 'DB columns' do | ||
it { is_expected.to have_db_column :name } | ||
end | ||
end |
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.
Could you please see if this solution work?