Skip to content

Commit

Permalink
Arrange test Rails application
Browse files Browse the repository at this point in the history
  • Loading branch information
simukappu committed Dec 31, 2019
1 parent 056cc4e commit 2084372
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 29 deletions.
4 changes: 2 additions & 2 deletions spec/concerns/renderable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
let(:group_text_key) { 'comment.reply' }
let(:plural_text_key) { 'comment.post' }
let(:simple_text_original) { 'Article has been created' }
let(:params_text_original) { "Article %{article_title} has been updated" }
let(:params_text_original) { 'Article "%{article_title}" has been updated' }
let(:plural_text_original_one) { "<p>%{notifier_name} posted a comment on your article %{article_title}</p>" }
let(:plural_text_original_other) { "<p>%{notifier_name} posted %{count} comments on your article %{article_title}</p>" }
let(:group_text_original) { "<p>%{notifier_name} and %{group_member_count} other people replied %{group_notification_count} times to your comment</p>" }
let(:params_text_embedded) { "Article bar has been updated" }
let(:params_text_embedded) { 'Article "bar" has been updated' }
let(:group_text_embedded) { "<p>foo and 3 other people replied 4 times to your comment</p>" }
let(:plural_text_embedded_one) { "<p>foo posted a comment on your article bar</p>" }
let(:plural_text_embedded_other) { "<p>foo posted 4 comments on your article bar</p>" }
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/view_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@

it "interpolates from parameters" do
notification.parameters = { "article_title" => "custom title" }
notification.key = 'article.update'
notification.key = 'article.destroy'
expect(render_notification notification, fallback: :text)
.to eq("Article custom title has been updated")
.to eq('The author removed an article "custom title"')
end
end

Expand Down
9 changes: 6 additions & 3 deletions spec/rails_app/app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ class ArticlesController < ApplicationController

# GET /articles
def index
@exists_user_notification_routes = respond_to?('user_notification_path')
@exists_admin_notification_routes = respond_to?('admin_notification_path')
@exists_notifications_routes = respond_to?('notifications_path')
@exists_user_notifications_routes = respond_to?('user_notifications_path')
@exists_admins_notifications_routes = respond_to?('admins_notifications_path')
@exists_admin_notifications_routes = respond_to?('admin_notifications_path')
@articles = Article.all.includes(:user)
end

Expand All @@ -29,7 +31,7 @@ def create
@article.user = current_user

if @article.save
@article.notify :users
@article.notify :users, key: 'article.create'
redirect_to @article, notice: 'Article was successfully created.'
else
render :new
Expand All @@ -39,6 +41,7 @@ def create
# PATCH/PUT /articles/1
def update
if @article.update(article_params)
@article.notify :users, key: 'article.update'
redirect_to @article, notice: 'Article was successfully updated.'
else
render :edit
Expand Down
8 changes: 4 additions & 4 deletions spec/rails_app/app/models/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class Admin < ActiveRecord::Base
subscription_allowed: true,
devise_resource: :user,
current_devise_target: ->(current_user) { current_user.admin },
printable_name: ->(admin) { "admin (#{admin.user.name})" },
printable_name: ->(admin) { "#{admin.user.name} (admin)" },
action_cable_allowed: true, action_cable_with_devise: true
end
end
else
require 'mongoid'
class Admin
Expand All @@ -28,7 +28,7 @@ class Admin
subscription_allowed: true,
devise_resource: :user,
current_devise_target: ->(current_user) { current_user.admin },
printable_name: ->(admin) { "admin (#{admin.user.name})" },
printable_name: ->(admin) { "#{admin.user.name} (admin)" },
action_cable_allowed: true, action_cable_with_devise: true
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<% content_for :notification_content, flush: true do %>
<div class='notification_list <%= notification.opened? ? "opened" : "unopened" %>'>
<div class="notification_list_cover"></div>
<div class="list_image"></div>
<div class="list_text_wrapper">
<p class="list_text">
<strong><%= notification.notifier.name %></strong> updated his or her article "<%= notification.notifiable.title %>".
<br>
<span><%= notification.created_at.strftime("%b %d %H:%M") %></span>
</p>
</div>
</div>
<% end %>

<div class='<%= "notification_#{notification.id}" %>'>
<% if notification.unopened? %>
<%= link_to open_notification_path_for(notification, parameters.slice(:routing_scope, :devise_default_routes).merge(reload: false)), method: :put, remote: true, class: "unopened_wrapper" do %>
<div class="unopened_circle"></div>
<div class="unopened_description_wrapper">
<p class="unopened_description">Open</p>
</div>
<% end %>
<%= link_to open_notification_path_for(notification, parameters.slice(:routing_scope, :devise_default_routes).merge(move: true)), method: :put do %>
<%= yield :notification_content %>
<% end %>
<div class="unopened_wrapper"></div>
<% else %>
<%= link_to move_notification_path_for(notification, parameters.slice(:routing_scope, :devise_default_routes)) do %>
<%= yield :notification_content %>
<% end %>
<% end %>

</div>

<style>
/* unopened_circle */
.unopened_wrapper{
position: absolute;
margin-top: 20px;
margin-left: 56px;
}
.unopened_wrapper .unopened_circle {
display: block;
width: 10px;
height: 10px;
position: absolute;
border-radius: 50%;
background-color: #27a5eb;
z-index: 2;
}
.unopened_wrapper:hover > .unopened_description_wrapper{
display: block;
}
.unopened_wrapper .unopened_description_wrapper {
display: none;
position: absolute;
margin-top: 26px;
margin-left: -24px;
}
.unopened_wrapper .unopened_description_wrapper .unopened_description {
position: absolute;
color: #fff;
font-size: 12px;
text-align: center;

border-radius: 4px;
background: rgba(0, 0, 0, 0.8);
padding: 4px 12px;
z-index: 999;
}
.unopened_wrapper .unopened_description_wrapper .unopened_description:before {
border: solid transparent;
border-top-width: 0;
content: "";
display: block;
position: absolute;
width: 0;
left: 50%;
top: -5px;
margin-left: -5px;
height: 0;
border-width: 0 5px 5px 5px;
border-color: transparent transparent rgba(0, 0, 0, 0.8) transparent;
z-index: 0;
}

/* list */
.notification_list {
padding: 15px 10px;
position: relative;
border-bottom: 1px solid #e5e5e5;
}
.notification_list.unopened {
background-color: #eeeff4;
}
.notification_list:hover {
background-color: #f8f9fb;
}
.notification_list:last-child {
border-bottom: none;
}
.notification_list:after{
content: "";
clear: both;
display: block;
}
.notification_list .notification_list_cover{
position: absolute;
opacity: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;

}
.notification_list .list_image {
float: left;
width: 40px;
height: 40px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
background-color: #979797;
}
.notification_list .list_text_wrapper {
float: left;
width: calc(100% - 60px);
margin-left: 20px;
}
.notification_list .list_text_wrapper .list_text {
color: #4f4f4f;
font-size: 14px;
line-height: 1.4;
margin-top: 0;
height: auto;
font-weight: normal;
}
.notification_list .list_text_wrapper .list_text strong{
font-weight: bold;
}
.notification_list .list_text_wrapper .list_text span {
color: #979797;
font-size: 13px;
}
</style>
56 changes: 50 additions & 6 deletions spec/rails_app/app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
<% if @exists_user_notification_routes %>
<% if @exists_notifications_routes %>
<section>
<h1>Authentecated User</h1>
<div class="list_wrapper">
<div class="list_image"></div>
<div class="list_description_wrapper">
<p class="list_description">
<% if user_signed_in? %>
<span><%= current_user.name %></span> · <%= current_user.email %> · <%= link_to 'Logout', destroy_user_session_path, method: :delete %><br>
<% else %>
<span>Not logged in</span> · <%= link_to 'Login', new_user_session_path %><br>
<% end %>
<%= link_to 'Notifications', notifications_path %> /
<% if User.subscription_enabled? %>
<%= link_to 'Subscriptions', subscriptions_path %>
<% end %>
</p>
</div>
</div>
</section>
<% end %>

<% if @exists_user_notifications_routes %>
<section>
<h1>Listing Users</h1>
<% User.all.each do |user| %>
<% User.all.order(:id).each do |user| %>
<div class="list_wrapper">
<div class="list_image"></div>
<div class="list_description_wrapper">
<p class="list_description">
<span><%= user.name %></span> · <%= user.email %><br>
<%= link_to 'Notifications', user_notifications_path(user) %>
<%= link_to 'Notifications', user_notifications_path(user) %> /
<% if User.subscription_enabled? %>
<%= link_to 'Subscriptions', user_subscriptions_path(user) %>
<% end %>
Expand All @@ -18,16 +40,38 @@
</section>
<% end %>

<% if @exists_admin_notification_routes %>
<% if @exists_admins_notifications_routes %>
<section>
<h1>Authentecated User as Admin</h1>
<div class="list_wrapper">
<div class="list_image"></div>
<div class="list_description_wrapper">
<p class="list_description">
<% if user_signed_in? %>
<span><%= current_user.name %></span> · <%= current_user.email %> <span><%= current_user.admin? ? "(admin)" : "(not admin)" %></span><br>
<% else %>
<span>Not logged in</span> · <%= link_to 'Login', new_user_session_path %><br>
<% end %>
<%= link_to 'Notifications', admins_notifications_path %> /
<% if User.subscription_enabled? %>
<%= link_to 'Subscriptions', admins_subscriptions_path %>
<% end %>
</p>
</div>
</div>
</section>
<% end %>

<% if @exists_admin_notifications_routes %>
<section>
<h1>Listing Admins</h1>
<% Admin.all.each do |admin| %>
<% Admin.all.order(:id).each do |admin| %>
<div class="list_wrapper">
<div class="list_image"></div>
<div class="list_description_wrapper">
<p class="list_description">
<span><%= admin.user.name %></span> · <%= admin.user.email %><br>
<%= link_to 'Notifications', admin_notifications_path(admin) %>
<%= link_to 'Notifications', admin_notifications_path(admin) %> /
<% if Admin.subscription_enabled? %>
<%= link_to 'Subscriptions', admin_subscriptions_path(admin) %>
<% end %>
Expand Down
18 changes: 8 additions & 10 deletions spec/rails_app/app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@
<%#= render_notifications_of current_user, fallback: :default_without_grouping, index_content: :with_attributes, with_group_members: true %>
<% end %>
</div>
<% if user_signed_in? and current_user.admin? and respond_to?('admins_notifications_path') %>
<div class="header_menu_wrapper">
<p>
<%= link_to "Admin notifications", admins_notifications_path %> /
<%= link_to "subscriptions", admins_subscriptions_path %>
</p>
</div>
<% end %>
<div class="header_menu_wrapper">
<p>
<%= link_to 'Preview email', "/rails/mailers" %>
<%= " · " unless user_signed_in? %>
<%= link_to 'Preview Email', "/rails/mailers" %>
<%= " · " if !user_signed_in? or (current_user.admin? and respond_to?('admins_notifications_path')) %>
</p>
</div>
<div class="header_menu_wrapper">
<p>
<%= link_to 'SPA', "/spa/" %>
<%= " · " %>
</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_app/config/locales/activity_notification.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ en:
create:
text: 'Article has been created'
update:
text: 'Article %{article_title} has been updated'
text: 'Article "%{article_title}" has been updated'
destroy:
text: 'Some user removed an article!'
text: 'The author removed an article "%{article_title}"'
comment:
create:
text: '%{notifier_name} posted a comment on the article "%{article_title}"'
Expand Down

0 comments on commit 2084372

Please sign in to comment.