Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file added app/assets/images/coffee.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/hero.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/hero2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require bootstrap-sprockets
//= require_tree .

4 changes: 4 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*=
@import "bootstrap-sprockets"
@import "bootstrap"
@import "font-awesome";
@import "bootstrap-social.less";
*/
@import "bootstrap-sprockets";
@import "bootstrap";


3 changes: 2 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ def index
end

def show
@articles = policy_scope(Article)
@comments = policy_scope(Comment)
@article = Article.friendly.find(params[:id])
redirect_to @article, status: :moved_permanently unless request.path == article_path(@article)
end
Expand All @@ -17,7 +19,6 @@ def new

def create
@article = Article.new(article_params)

if @article.save
redirect_to @article, notice: 'Article was successfully created.'
current_user.articles << @article
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class CommentsController < ApplicationController
before_action :authorize_comment, only: [:edit, :update]
before_action :set_comment, only: [:show, :edit, :update, :destroy]

def index
@article = Article.friendly.find(params[:article_id])
@comments = @article.comments
Expand Down Expand Up @@ -52,7 +55,15 @@ def destroy

private

def set_comment
@comment = Comment.find(params[:id])
end

def authorize_comment
authorize Comment
end

def comment_params
params.require(:comment).permit(:commenter_name, :content)
params.require(:comment).permit(:commenter_name, :content, (:approved if current_user.role == "editor"))
end
end
2 changes: 1 addition & 1 deletion app/models/article.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Article < ActiveRecord::Base
belongs_to :author, class_name: "User"
belongs_to :user #:author, class_name: "User"
has_many :comments
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable

enum role: [:null_user, :author, :editor]
enum role: [:null_user, :author, :editor, :twitter_user]
after_initialize :set_default_role, if: :new_record?
has_many :articles, foreign_key: "author_id"

Expand Down
4 changes: 4 additions & 0 deletions app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def editor?
false
end

def unauthenticated?
true
end

def author?
false
end
Expand Down
11 changes: 9 additions & 2 deletions app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
class CommentPolicy < ApplicationPolicy
class Scope < Scope
def initialize(user, scope)
@user = user
@scope = scope
end

def resolve
if user.editor?
scope.all
elsif !user.nil?
scope.all
else
scope.where(published: true)
scope.where(approved: true)
end
end
end

def create?
user.editor? || user.author?
!user.unauthenticated?
end

def update?
Expand Down
18 changes: 13 additions & 5 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@
<p><strong>By:</strong> <%= @article.author_id %></p>
</p>
<% if @article.published? %>
<p>Status: Published</p>
<p>Status: Published</p>
<% else %>
<p>Status: Unpublished</p>
<% end %>

<%= link_to 'Edit Article', edit_article_path(@article) %> |
<%= link_to 'Delete Article', @article, method: :delete, data: {confirm: 'Are you sure?' } %> |
<% @articles.each do |article| %>
<% if policy(article).update? %>
<%= link_to 'Edit Article', edit_article_path(@article) %> |
<%= link_to 'Delete Article', @article, method: :delete, data: {confirm: 'Are you sure?' } %> |
<% end %>
<% end %>
<%= link_to 'Back', articles_path %>


<h3>Comments</h3>
<h5><%= link_to 'Comment', new_article_comment_path(@article) %></h5>
<% @article.comments.each do |comment| %>
<% if policy(comment).create? %>
<h3>Comments</h3>
<h5><%= link_to 'Comment', new_article_comment_path(@article) %></h5>
<% end %>
<% end %>

<% @article.comments.each do |c| %>
<p><b><%=h c.commenter_name %>:</b> <em><%=h c.content %></em></p>
Expand Down
12 changes: 6 additions & 6 deletions app/views/comments/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
<hr class="star-primary">
</div>
</div>
<%# if ArticlePolicy.new(current_user, @article).create? %>
<% if ArticlePolicy.new(current_user, @article).create? %>
<%= link_to 'New comment', new_article_comment_path %>
<%# end %>
<% end %>

<ul>
<% @comments.each do |comment| %>
<li class="comment" id="<%= dom_id(comment) %>"></li>
<p><b><%= comment.commenter_name %></b> <%=comment.content %></p>
<%# if policy(comment).update? %>
<% if policy(comment).update? %>
<%= link_to 'Edit', edit_article_comment_path(@article, comment) %>
<%# end %>
<%# if policy(comment).destroy? %>
<% end %>
<% if policy(comment).destroy? %>
<%= link_to 'Delete', article_comment_path(@article, comment), method: :delete, data: {confirm: 'Are you sure?' } %>
<%# end %>
<% end %>
</li>
<% end %>
</ul>
Expand Down
20 changes: 11 additions & 9 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
<% end %>

<% if f.object.password_required? %>
<div>
<%= f.label :password %> <i>(password)</i><br />
<%= f.password_field :password, :autocomplete => "off" %>
</div>
<div>
<%= f.label :password %> <i>(password)</i><br />
<%= f.password_field :password, :autocomplete => "off" %>
</div>

<div>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</div>
<div>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</div>
<% end %>

<div class="actions"><%= f.submit, "Sign In" %></div>
<div>
<%= f.submit "Sign Up" %>
</div>

<%= link_to 'Back', :back %>
<% end %>
22 changes: 22 additions & 0 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<footer class = "footer">
<nav>
<ul id="menu-main" class="list-inline text-center">
<!-- Twitter -->
<li class="text-center">
<%= link_to image_tag('twitter.png', alt: "Twitter Logo", class: "social-icon"), "https://twitter.com/AmandaKom", target: "_blank" %>
</li>

<!-- LinkedIn -->
<li class="text-center">
<%= link_to image_tag('linkedin.png', alt: "LinkedIn Logo", class: "social-icon"), "https://linkedin.com/in/amandakom", target: "_blank" %>
</li>

<!-- GitHub -->
<li class="text-center">
<%= link_to image_tag('github.png', alt: "GitHub Logo", class: "social-icon"), "https://github.com/mandarenee", target: "_blank" %>
<li>
</ul>
</nav>
<p class="text-center">© 2015 Amanda Kom</p>
</footer>

71 changes: 30 additions & 41 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,37 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
</head>

<header>
<div class="container">
<div class="row">
<div class="col-lg-12" align="middle">
<div class="intro-text">
<h2><span class="name">Manda Kom</span></h2>
<span class="skills">Rails Web Developer</span>
<br/>
<img src="<%= asset_url('Flowers.png') %>" width="30%">
</div>
</div>
</div>
</div>
</header>

<body>

<%= render 'shared/navigation' %>

<div id="sidebar" class="col-xs-2 bg-danger">
<h3>Viu as flores?<br/></h3>
<h4>Que linda!</h4>
</div>

<% flash.each do |key, value| %>
<div class="alert-box round <%= flash_class(key) %>">
<%= value %>
<header class = " navbar ">
<img src="<%= asset_url('hero2.jpg') %>" width="100%">
<div class="container">
<% if current_user %>
<p align="right">
Signed in as <%= current_user.name %>. Not you? <%= link_to 'Sign Out', destroy_user_session_path, :method => :delete %>
</p>
<% else %>
<p align="right"><%= link_to 'Sign Up', new_user_registration_path %>, <%= link_to 'Sign In', new_user_session_path %>, or <%= link_to 'Sign in with Twitter', user_omniauth_authorize_path(:twitter) %></p>
<% end %>
<% flash.each do |key, value| %>
<div class="alert-box round <%= flash_class(key) %>">
<%= value %>
</div>
<% end %>

<nav>
<ul id="menu-main" class="nav nav-tabs text-center">
<li role="presentation" class="text-center"><%= link_to 'About Me', welcome_path %></li>
<li role="presentation" class="text-center"><%= link_to 'Portfolio', projects_path %></li>
<li role="presentation" class="text-center"><%= link_to 'Blog', articles_path %></li>
</ul>
</nav>
</div>
<% end %>

<%= link_to 'Sign Up', new_user_registration_path %>

<div id="main-container" class="container-fluid">
<div class="row">
<div id="main-content" class="col-xs-9">
<%= yield %>
</div>
</div>
</header>
<body>
<div class = "container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>

</body>
</body>
</html>
36 changes: 0 additions & 36 deletions app/views/shared/_navigation.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions db/migrate/20150321233759_add_author_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAuthorToArticles < ActiveRecord::Migration
def change
add_column :articles, :author, :string
end
end
10 changes: 5 additions & 5 deletions test/features/articles/write_new_article_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Then the article should be created and displayed
page.must_have_content "Article was successfully created"
page.must_have_content "it's worth it"
page.text.must_include "test1@test.com"
page.text.must_include "Strawberry Shortcake"
page.text.must_include "Status: Unpublished"
end

Expand All @@ -34,8 +34,8 @@
sign_in(:user)
visit new_article_path
page.must_have_field('Published')
fill_in "Title", with: articles(:UserTest).title
fill_in "Body", with: articles(:UserTest).body
fill_in "Title", with: articles(:OnePublished).title
fill_in "Body", with: articles(:OnePublished).body
check "Published"
click_on "Create Article"
page.text.must_include "Status: Published"
Expand All @@ -59,8 +59,8 @@
sign_in(:editor)
visit new_article_path
page.must_have_field('Published')
fill_in "Title", with: articles(:UserUnpublished).title
fill_in "Body", with: articles(:UserUnpublished).body
fill_in "Title", with: articles(:OneUnpublished).title
fill_in "Body", with: articles(:OneUnpublished).body
check "Published"
click_on "Create Article"
page.text.must_include "Status: Published"
Expand Down
5 changes: 1 addition & 4 deletions test/features/auth/sign_up_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require "test_helper"

feature "
As a site visitor, I want to be able to sign up for an account,
so that I can perform actions that require me to be logged in.
" do
feature "Sign up for an account" do
scenario "sign up" do
sign_up

Expand Down
Loading