From 823c6d8f94ca29522668f467d2e26e6ecfe782be Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 16:27:13 +0100 Subject: [PATCH 01/17] add author field to new article add author column to article db display author on article show page validate and sanitze author params --- app/controllers/articles_controller.rb | 2 +- app/models/article.rb | 2 +- app/views/articles/new.html.haml | 4 ++++ app/views/articles/show.html.haml | 3 +++ db/migrate/20180318150215_add_author_to_article.rb | 5 +++++ db/schema.rb | 3 ++- 6 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20180318150215_add_author_to_article.rb diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index ed262dc..c2a5399 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -22,6 +22,6 @@ def show private def article_params - params[:article].permit(:title, :content) + params[:article].permit(:title, :content, :author) end end diff --git a/app/models/article.rb b/app/models/article.rb index d9c8f31..2491198 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,3 +1,3 @@ class Article < ApplicationRecord - validates :title, :content, presence: true + validates :title, :content, :author, presence: true end diff --git a/app/views/articles/new.html.haml b/app/views/articles/new.html.haml index f2168b1..ba60141 100644 --- a/app/views/articles/new.html.haml +++ b/app/views/articles/new.html.haml @@ -3,6 +3,10 @@ = form.label :title %br/ = form.text_field :title, id: :article_title + %p + = form.label :author + %br/ + = form.text_field :author, id: :article_author %p = form.label :content %br/ diff --git a/app/views/articles/show.html.haml b/app/views/articles/show.html.haml index da795c2..558fec5 100644 --- a/app/views/articles/show.html.haml +++ b/app/views/articles/show.html.haml @@ -1,6 +1,9 @@ %p %strong Title: = @article.title +%p + %strong Authors: + =@article.author %p %strong Text: = @article.content diff --git a/db/migrate/20180318150215_add_author_to_article.rb b/db/migrate/20180318150215_add_author_to_article.rb new file mode 100644 index 0000000..9cd6e53 --- /dev/null +++ b/db/migrate/20180318150215_add_author_to_article.rb @@ -0,0 +1,5 @@ +class AddAuthorToArticle < ActiveRecord::Migration[5.2] + def change + add_column :articles, :author, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 143928f..0464768 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_17_113155) do +ActiveRecord::Schema.define(version: 2018_03_18_150215) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,7 @@ t.text "content" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "author" end create_table "users", force: :cascade do |t| From 899d977160e3db399d21e6bfdf71d33704f4b6a5 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 17:51:58 +0100 Subject: [PATCH 02/17] add author and article associations add validation for author add tests for associations --- app/models/article.rb | 2 ++ app/models/author.rb | 5 +++++ features/support/warden.rb | 2 +- spec/factories/authors.rb | 5 +++++ spec/models/article_spec.rb | 6 +++++- spec/models/author_spec.rb | 17 +++++++++++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/models/author.rb create mode 100644 spec/factories/authors.rb create mode 100644 spec/models/author_spec.rb diff --git a/app/models/article.rb b/app/models/article.rb index 2491198..208dcfd 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,3 +1,5 @@ class Article < ApplicationRecord validates :title, :content, :author, presence: true + + belongs_to :author end diff --git a/app/models/author.rb b/app/models/author.rb new file mode 100644 index 0000000..bfb4409 --- /dev/null +++ b/app/models/author.rb @@ -0,0 +1,5 @@ +class Author < ApplicationRecord + validates :author, presence: true + + has_many :articles +end diff --git a/features/support/warden.rb b/features/support/warden.rb index 9e4419b..35e3991 100644 --- a/features/support/warden.rb +++ b/features/support/warden.rb @@ -1,3 +1,3 @@ Warden.test_mode! World Warden::Test::Helpers -After { Warden.test_reset! } \ No newline at end of file +After { Warden.test_reset! } diff --git a/spec/factories/authors.rb b/spec/factories/authors.rb new file mode 100644 index 0000000..0cfb836 --- /dev/null +++ b/spec/factories/authors.rb @@ -0,0 +1,5 @@ +FactoryBot.define do + factory :author do + authors 'Man McMaster' + end +end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 63084a4..19c2d6c 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -8,7 +8,7 @@ describe 'Factory' do it 'should have valid Factory' do - expect(create(:article)).to be_valid + expect(create(:author)).to be_valid end end @@ -16,4 +16,8 @@ it { is_expected.to validate_presence_of :title } it { is_expected.to validate_presence_of :content } end + + describe 'Associations' do + it { should belong_to :author } + end end diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb new file mode 100644 index 0000000..b4b1940 --- /dev/null +++ b/spec/models/author_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe Author, type: :model do + describe 'Associations' do + it { should have_many :article} + end + + describe 'Validations' do + it { is_expected.to validate_presence_of :author } + end + + describe 'Factory' do + it 'should have valid Factory' do + expect(create(:author)).to be_valid + end + end +end From 4115a2d55415359d76d05fd21d7d6a4e8872e973 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 18:31:41 +0100 Subject: [PATCH 03/17] create author table add author ref to article fix author tests --- db/migrate/20180318150215_add_author_to_article.rb | 5 ----- db/migrate/20180318172631_create_author.rb | 7 +++++++ db/migrate/20180318173006_add_author_ref_to_article.rb | 5 +++++ db/schema.rb | 9 ++++++++- spec/models/author_spec.rb | 2 +- 5 files changed, 21 insertions(+), 7 deletions(-) delete mode 100644 db/migrate/20180318150215_add_author_to_article.rb create mode 100644 db/migrate/20180318172631_create_author.rb create mode 100644 db/migrate/20180318173006_add_author_ref_to_article.rb diff --git a/db/migrate/20180318150215_add_author_to_article.rb b/db/migrate/20180318150215_add_author_to_article.rb deleted file mode 100644 index 9cd6e53..0000000 --- a/db/migrate/20180318150215_add_author_to_article.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAuthorToArticle < ActiveRecord::Migration[5.2] - def change - add_column :articles, :author, :string - end -end diff --git a/db/migrate/20180318172631_create_author.rb b/db/migrate/20180318172631_create_author.rb new file mode 100644 index 0000000..24b7bf8 --- /dev/null +++ b/db/migrate/20180318172631_create_author.rb @@ -0,0 +1,7 @@ +class CreateAuthor < ActiveRecord::Migration[5.2] + def change + create_table :authors do |t| + t.string :author + end + end +end diff --git a/db/migrate/20180318173006_add_author_ref_to_article.rb b/db/migrate/20180318173006_add_author_ref_to_article.rb new file mode 100644 index 0000000..abe4a88 --- /dev/null +++ b/db/migrate/20180318173006_add_author_ref_to_article.rb @@ -0,0 +1,5 @@ +class AddAuthorRefToArticle < ActiveRecord::Migration[5.2] + def change + add_reference :articles, :author, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 0464768..6d3f66b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_18_150215) do +ActiveRecord::Schema.define(version: 2018_03_18_173006) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,12 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "author" + t.bigint "author_id" + t.index ["author_id"], name: "index_articles_on_author_id" + end + + create_table "authors", force: :cascade do |t| + t.string "author" end create_table "users", force: :cascade do |t| @@ -41,4 +47,5 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "articles", "authors" end diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb index b4b1940..85d257c 100644 --- a/spec/models/author_spec.rb +++ b/spec/models/author_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Author, type: :model do describe 'Associations' do - it { should have_many :article} + it { should have_many :articles} end describe 'Validations' do From 4242955f1c6119df8c4542944a552916d8ff6d31 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 18:32:25 +0100 Subject: [PATCH 04/17] create author table add author ref to article fix author tests --- spec/models/article_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 19c2d6c..55ac129 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -8,7 +8,7 @@ describe 'Factory' do it 'should have valid Factory' do - expect(create(:author)).to be_valid + expect(create(:article)).to be_valid end end From e9bdf7545dabcde8fc694a07f7b528d58df58d41 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 18:33:47 +0100 Subject: [PATCH 05/17] fix factory bot tests rspec all green --- spec/factories/authors.rb | 2 +- spec/models/article_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/factories/authors.rb b/spec/factories/authors.rb index 0cfb836..5df76f1 100644 --- a/spec/factories/authors.rb +++ b/spec/factories/authors.rb @@ -1,5 +1,5 @@ FactoryBot.define do factory :author do - authors 'Man McMaster' + author 'Man McMaster' end end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 55ac129..19c2d6c 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -8,7 +8,7 @@ describe 'Factory' do it 'should have valid Factory' do - expect(create(:article)).to be_valid + expect(create(:author)).to be_valid end end From 43c3821f25b40dedac57856e93a60aa44f97dffe Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Sun, 18 Mar 2018 20:49:36 +0100 Subject: [PATCH 06/17] edit article path in controller --- app/controllers/articles_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index c2a5399..bd98898 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -8,7 +8,7 @@ def create @article = Article.new(article_params) if @article.save flash[:success] = "Article was successfully created." - redirect_to @article + redirect_to article_path(@article) else flash[:error] = "Field cannot be blank" render 'new' From b4f7f638e2219cf82db1cd60cd60ecad54d02b9d Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 10:23:41 +0100 Subject: [PATCH 07/17] rollback author db changes change unnecessary code --- app/controllers/articles_controller.rb | 2 +- app/views/articles/show.html.haml | 2 +- db/schema.rb | 9 +-------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index bd98898..c2a5399 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -8,7 +8,7 @@ def create @article = Article.new(article_params) if @article.save flash[:success] = "Article was successfully created." - redirect_to article_path(@article) + redirect_to @article else flash[:error] = "Field cannot be blank" render 'new' diff --git a/app/views/articles/show.html.haml b/app/views/articles/show.html.haml index 558fec5..9c07c75 100644 --- a/app/views/articles/show.html.haml +++ b/app/views/articles/show.html.haml @@ -3,7 +3,7 @@ = @article.title %p %strong Authors: - =@article.author + =@article.authors %p %strong Text: = @article.content diff --git a/db/schema.rb b/db/schema.rb index 6d3f66b..0464768 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_18_173006) do +ActiveRecord::Schema.define(version: 2018_03_18_150215) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,12 +21,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "author" - t.bigint "author_id" - t.index ["author_id"], name: "index_articles_on_author_id" - end - - create_table "authors", force: :cascade do |t| - t.string "author" end create_table "users", force: :cascade do |t| @@ -47,5 +41,4 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end - add_foreign_key "articles", "authors" end From adf07826cdf652c7048c65bdb2820740c1a12c00 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 10:25:38 +0100 Subject: [PATCH 08/17] delete author class --- app/controllers/articles_controller.rb | 2 +- app/models/author.rb | 5 ----- db/migrate/20180318172631_create_author.rb | 7 ------- .../20180318173006_add_author_ref_to_article.rb | 5 ----- spec/factories/authors.rb | 5 ----- spec/models/author_spec.rb | 17 ----------------- 6 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 app/models/author.rb delete mode 100644 db/migrate/20180318172631_create_author.rb delete mode 100644 db/migrate/20180318173006_add_author_ref_to_article.rb delete mode 100644 spec/factories/authors.rb delete mode 100644 spec/models/author_spec.rb diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index c2a5399..ed262dc 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -22,6 +22,6 @@ def show private def article_params - params[:article].permit(:title, :content, :author) + params[:article].permit(:title, :content) end end diff --git a/app/models/author.rb b/app/models/author.rb deleted file mode 100644 index bfb4409..0000000 --- a/app/models/author.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Author < ApplicationRecord - validates :author, presence: true - - has_many :articles -end diff --git a/db/migrate/20180318172631_create_author.rb b/db/migrate/20180318172631_create_author.rb deleted file mode 100644 index 24b7bf8..0000000 --- a/db/migrate/20180318172631_create_author.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CreateAuthor < ActiveRecord::Migration[5.2] - def change - create_table :authors do |t| - t.string :author - end - end -end diff --git a/db/migrate/20180318173006_add_author_ref_to_article.rb b/db/migrate/20180318173006_add_author_ref_to_article.rb deleted file mode 100644 index abe4a88..0000000 --- a/db/migrate/20180318173006_add_author_ref_to_article.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAuthorRefToArticle < ActiveRecord::Migration[5.2] - def change - add_reference :articles, :author, foreign_key: true - end -end diff --git a/spec/factories/authors.rb b/spec/factories/authors.rb deleted file mode 100644 index 5df76f1..0000000 --- a/spec/factories/authors.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :author do - author 'Man McMaster' - end -end diff --git a/spec/models/author_spec.rb b/spec/models/author_spec.rb deleted file mode 100644 index 85d257c..0000000 --- a/spec/models/author_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rails_helper' - -RSpec.describe Author, type: :model do - describe 'Associations' do - it { should have_many :articles} - end - - describe 'Validations' do - it { is_expected.to validate_presence_of :author } - end - - describe 'Factory' do - it 'should have valid Factory' do - expect(create(:author)).to be_valid - end - end -end From 88cf87cd5ee0ed768d20e020341983824f811730 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 10:40:32 +0100 Subject: [PATCH 09/17] generate migration for user ref to articles make correct assocations between user and articles --- app/models/article.rb | 4 ++-- app/models/user.rb | 2 ++ db/migrate/20180319093819_add_user_ref_to_articles.rb | 5 +++++ db/schema.rb | 5 ++++- spec/models/article_spec.rb | 4 ++-- spec/models/user_spec.rb | 4 ++++ 6 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20180319093819_add_user_ref_to_articles.rb diff --git a/app/models/article.rb b/app/models/article.rb index 208dcfd..7bee3ac 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,5 +1,5 @@ class Article < ApplicationRecord - validates :title, :content, :author, presence: true + validates :title, :content, presence: true - belongs_to :author + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index 57eebca..cd93113 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,6 @@ class User < ApplicationRecord devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable + + has_many :articles end diff --git a/db/migrate/20180319093819_add_user_ref_to_articles.rb b/db/migrate/20180319093819_add_user_ref_to_articles.rb new file mode 100644 index 0000000..c08d320 --- /dev/null +++ b/db/migrate/20180319093819_add_user_ref_to_articles.rb @@ -0,0 +1,5 @@ +class AddUserRefToArticles < ActiveRecord::Migration[5.2] + def change + add_reference :articles, :user, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 0464768..3ae9369 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_03_18_150215) do +ActiveRecord::Schema.define(version: 2018_03_19_093819) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -21,6 +21,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "author" + t.bigint "user_id" + t.index ["user_id"], name: "index_articles_on_user_id" end create_table "users", force: :cascade do |t| @@ -41,4 +43,5 @@ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end + add_foreign_key "articles", "users" end diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 19c2d6c..d79fab3 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -8,7 +8,7 @@ describe 'Factory' do it 'should have valid Factory' do - expect(create(:author)).to be_valid + expect(create(:user)).to be_valid end end @@ -18,6 +18,6 @@ end describe 'Associations' do - it { should belong_to :author } + it { should belong_to :user } end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e67490a..f1434cc 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -11,4 +11,8 @@ expect(create(:user)).to be_valid end end + + describe 'Associations' do + it { should have_many :articles } + end end From 77ec4b534c513d863de6396a962e20cc187586d9 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 11:41:53 +0100 Subject: [PATCH 10/17] delete author field add user logged in to create article tests --- app/controllers/articles_controller.rb | 2 +- app/views/articles/new.html.haml | 4 ---- app/views/articles/show.html.haml | 4 ++-- db/schema.rb | 1 - features/create_articles.feature | 4 ++++ 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index ed262dc..8116e89 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -22,6 +22,6 @@ def show private def article_params - params[:article].permit(:title, :content) + params[:article].permit(:title, :content, :user_id) end end diff --git a/app/views/articles/new.html.haml b/app/views/articles/new.html.haml index ba60141..f2168b1 100644 --- a/app/views/articles/new.html.haml +++ b/app/views/articles/new.html.haml @@ -3,10 +3,6 @@ = form.label :title %br/ = form.text_field :title, id: :article_title - %p - = form.label :author - %br/ - = form.text_field :author, id: :article_author %p = form.label :content %br/ diff --git a/app/views/articles/show.html.haml b/app/views/articles/show.html.haml index 9c07c75..db6a32f 100644 --- a/app/views/articles/show.html.haml +++ b/app/views/articles/show.html.haml @@ -2,8 +2,8 @@ %strong Title: = @article.title %p - %strong Authors: - =@article.authors + %strong Author + =@article.user %p %strong Text: = @article.content diff --git a/db/schema.rb b/db/schema.rb index 3ae9369..104c7e9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -20,7 +20,6 @@ t.text "content" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "author" t.bigint "user_id" t.index ["user_id"], name: "index_articles_on_user_id" end diff --git a/features/create_articles.feature b/features/create_articles.feature index eb8a553..f312c14 100644 --- a/features/create_articles.feature +++ b/features/create_articles.feature @@ -5,6 +5,10 @@ Feature: Create articles Background: Given I visit the Homepage + Given the following user exists + | email | password | password_confirmation | + | harald@norge.no | OsloOslo123 | OsloOslo123 | + And I am logged in as "harald@norge.no" Scenario: Successfully create an article When I click "New Article" link From c3d613e7e454c853d43a12b59c51c613448b0bca Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 12:42:21 +0100 Subject: [PATCH 11/17] set articles creator to current user all tests green --- app/controllers/articles_controller.rb | 5 +++-- features/create_articles.feature | 1 + features/step_definitions/create_articles_steps.rb | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 8116e89..3f1899c 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -6,9 +6,10 @@ def new def create @article = Article.new(article_params) + @article.user = current_user if @article.save flash[:success] = "Article was successfully created." - redirect_to @article + redirect_to article_path(@article) else flash[:error] = "Field cannot be blank" render 'new' @@ -22,6 +23,6 @@ def show private def article_params - params[:article].permit(:title, :content, :user_id) + params.require(:article).permit(:title, :content) end end diff --git a/features/create_articles.feature b/features/create_articles.feature index f312c14..fd68a6a 100644 --- a/features/create_articles.feature +++ b/features/create_articles.feature @@ -15,6 +15,7 @@ Feature: Create articles Then I fill in "Title" with "A Whole New World" And I fill in "Content" with "A new fantastic point of view" And I click "Create Article" button + And I save and open page Then I should be on "A Whole New World" page And I should see "Article was successfully created." And I should see "A Whole New World" diff --git a/features/step_definitions/create_articles_steps.rb b/features/step_definitions/create_articles_steps.rb index b820f3f..7762ac9 100644 --- a/features/step_definitions/create_articles_steps.rb +++ b/features/step_definitions/create_articles_steps.rb @@ -10,6 +10,10 @@ fill_in(input, with: value) end +Then("I save and open page") do + save_and_open_page +end + When("I click {string} button") do |string| click_button string end From dd938b9d290ee3460a514ac5fb45212d8947a59e Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 13:54:32 +0100 Subject: [PATCH 12/17] set author name to user email address take out show page from tests --- app/controllers/articles_controller.rb | 2 +- app/views/articles/show.html.haml | 4 ++-- features/create_articles.feature | 1 - features/step_definitions/create_articles_steps.rb | 4 ---- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 3f1899c..884b3e0 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -9,7 +9,7 @@ def create @article.user = current_user if @article.save flash[:success] = "Article was successfully created." - redirect_to article_path(@article) + redirect_to @article else flash[:error] = "Field cannot be blank" render 'new' diff --git a/app/views/articles/show.html.haml b/app/views/articles/show.html.haml index db6a32f..a7cc220 100644 --- a/app/views/articles/show.html.haml +++ b/app/views/articles/show.html.haml @@ -2,8 +2,8 @@ %strong Title: = @article.title %p - %strong Author - =@article.user + %strong Author: + =@article.user.email %p %strong Text: = @article.content diff --git a/features/create_articles.feature b/features/create_articles.feature index fd68a6a..f312c14 100644 --- a/features/create_articles.feature +++ b/features/create_articles.feature @@ -15,7 +15,6 @@ Feature: Create articles Then I fill in "Title" with "A Whole New World" And I fill in "Content" with "A new fantastic point of view" And I click "Create Article" button - And I save and open page Then I should be on "A Whole New World" page And I should see "Article was successfully created." And I should see "A Whole New World" diff --git a/features/step_definitions/create_articles_steps.rb b/features/step_definitions/create_articles_steps.rb index 7762ac9..b820f3f 100644 --- a/features/step_definitions/create_articles_steps.rb +++ b/features/step_definitions/create_articles_steps.rb @@ -10,10 +10,6 @@ fill_in(input, with: value) end -Then("I save and open page") do - save_and_open_page -end - When("I click {string} button") do |string| click_button string end From ae54e9fbcadf2bd4368086579fd337c7d1572e11 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Mon, 19 Mar 2018 14:06:38 +0100 Subject: [PATCH 13/17] fix merge conflict --- app/models/article.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/article.rb b/app/models/article.rb index 7bee3ac..1668eec 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,4 +2,5 @@ class Article < ApplicationRecord validates :title, :content, presence: true belongs_to :user + end From 9dc83cf8923195a8acb1d34847f5fe8e799f67ff Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Thu, 22 Mar 2018 11:34:48 +0100 Subject: [PATCH 14/17] edit factory create --- spec/models/article_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 61dddfd..dd1f0a6 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -8,7 +8,7 @@ describe 'Factory' do it 'should have valid Factory' do - expect(create(:user)).to be_valid + expect(create(:article)).to be_valid end end From 8943240c06c197c34121b7ba72cfc9199bdfc699 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Thu, 22 Mar 2018 13:37:39 +0100 Subject: [PATCH 15/17] fix author display --- app/views/articles/show.html.haml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/articles/show.html.haml b/app/views/articles/show.html.haml index 1dbd176..7762ce1 100644 --- a/app/views/articles/show.html.haml +++ b/app/views/articles/show.html.haml @@ -3,7 +3,10 @@ = @article.title %p %strong Author: - =@article.user.email + - if @article.user + = @article.user.email + - else + = "Anonymous" %p %strong Text: = @article.content From 92d36d63ce51e975d5f209e2a53dd64385e97981 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Thu, 22 Mar 2018 13:40:17 +0100 Subject: [PATCH 16/17] delete chrome driver binary --- features/support/env.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index fb15c09..eb67a0f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -20,7 +20,6 @@ options = Selenium::WebDriver::Chrome::Options.new( implicit_wait: 60, args: %w(disable-popup-blocking disable-infobars), - binary: '/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome' ) Capybara::Selenium::Driver.new( From 9d66c96dadf0e29de62c4a67eca3a08795b405f1 Mon Sep 17 00:00:00 2001 From: Aiden_Jubelin Date: Thu, 22 Mar 2018 13:43:57 +0100 Subject: [PATCH 17/17] remove comma --- features/support/env.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/support/env.rb b/features/support/env.rb index eb67a0f..014cc9a 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -19,7 +19,7 @@ Capybara.register_driver :selenium do |app| options = Selenium::WebDriver::Chrome::Options.new( implicit_wait: 60, - args: %w(disable-popup-blocking disable-infobars), + args: %w(disable-popup-blocking disable-infobars) ) Capybara::Selenium::Driver.new(