Skip to content
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

Dump import #42

Merged
merged 15 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#28 #29 Add tests for articles
  • Loading branch information
clairezed committed Mar 29, 2018
commit eddeeb63c3052172f798c5f49004dada30bc042e
2 changes: 2 additions & 0 deletions app/models/custom/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Article < ActiveRecord::Base

validates :title, presence: true
validates :status, presence: true, inclusion: { in: VALID_STATUSES }
validates :author, presence: true
validates :content, presence: true

scope :published, -> { where(status: 'published').order('id DESC') }

Expand Down
2 changes: 1 addition & 1 deletion app/views/custom/articles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<main>
<div class="row">
<%# TODO - change id and class to smth dedicated to articles %>
<div class="small-12 column">
<div id="articles" class="small-12 column">
<% if @articles.any? %>
<%= render partial: 'articles/article', collection: @articles %>
<%= paginate @articles %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/custom/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<%= render '/shared/author_info', resource: @article %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l @article.created_at.to_date %>
<!--span class="bullet">&nbsp;&bull;&nbsp;</span-->
<%# geozone_name(@article) %>
</div>

<%= image_tag @article.image_url(:large), alt: @article.image.title, class: 'article-image' %>
<% if @article.image.present? %>
<%= image_tag @article.image_url(:large), alt: @article.image.title, class: 'article-image' %>
<% end %>

<%= safe_html_with_links @article.content.html_safe %>

Expand Down
17 changes: 17 additions & 0 deletions spec/custom/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FactoryBot.define do
factory :article do
sequence(:title) { |n| "Titre #{n}" }
association :author, factory: :user
content "Article body"

trait :published do
status 'published'
end

trait :draft do
status 'draft'
end

end

end
38 changes: 38 additions & 0 deletions spec/custom/features/articles_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# coding: utf-8
require 'rails_helper'

feature 'Articles' do

scenario 'Index' do
published_articles = [create(:article, :published), create(:article, :published)]
create(:article, :draft)

visit articles_path

expect(page).to have_selector('#articles .article', count: 2)
published_articles.each do |article|
within('#articles') do
expect(page).to have_content article.title
expect(page).to have_css("a[href='#{article_path(article)}']", text: article.title)
end
end
end

scenario 'Show' do
article = create(:article, :published)

visit article_path(article)

expect(page).to have_content article.title
expect(page).to have_content "Article body"
expect(page).to have_content article.author.name
expect(page).to have_content I18n.l(article.created_at.to_date)
expect(page).to have_selector(avatar(article.author.name))
expect(page.html).to include "<title>#{article.title}</title>"

within('.social-share-button') do
expect(page.all('a').count).to be(4) # Twitter, Facebook, Google+, Telegram
end
end

end
10 changes: 10 additions & 0 deletions spec/custom/models/article_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# coding: utf-8
require 'rails_helper'

describe Article do
let(:article) { build(:article) }

it "is valid" do
expect(article).to be_valid
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
Dir["./spec/custom/support/**/*.rb"].sort.each { |f| require f }
Dir["./spec/custom/factories.rb"].sort.each { |f| require f }

RSpec.configure do |config|
config.use_transactional_fixtures = false
Expand Down