docbrown/spec/requests/articles/articles_create_spec.rb
Anna Buianova 9b04654e3b Refactor articles creation (#3797)
* Refactor articles creation

* Create article from /admin via a service for consistency

* Move articles destroy logic into Articles::Destroyer
2019-08-23 14:43:29 -04:00

50 lines
1.5 KiB
Ruby

require "rails_helper"
RSpec.describe "ArticlesCreate", type: :request do
let(:user) { create(:user, :org_member) }
before do
sign_in user
end
it "creates ordinary article with proper params" do
new_title = "NEW TITLE #{rand(100)}"
post "/articles", params: {
article: { title: new_title, body_markdown: "Yo ho ho#{rand(100)}", tag_list: "yo" }
}
expect(Article.last.user_id).to eq(user.id)
end
it "creates article with front matter params" do
post "/articles", params: {
article: {
body_markdown: "---\ntitle: hey hey hahuu\npublished: false\n---\nYo ho ho#{rand(100)}",
tag_list: "yo"
}
}
expect(Article.last.title).to eq("hey hey hahuu")
end
it "creates article with front matter params and org" do
user_org_id = user.organizations.first.id
post "/articles", params: {
article: {
body_markdown: "---\ntitle: hey hey hahuu\npublished: false\n---\nYo ho ho#{rand(100)}",
tag_list: "yo",
organization_id: user_org_id
}
}
expect(Article.last.organization_id).to eq(user_org_id)
end
it "creates series when series is created with frontmatter" do
new_title = "NEW TITLE #{rand(100)}"
post "/articles", params: {
article: {
title: new_title,
body_markdown: "---\ntitle: hey hey hahuu\npublished: false\nseries: helloyo\n---\nYo ho ho#{rand(100)}"
}
}
expect(Collection.last.slug).to eq("helloyo")
end
end