Skip to content

Commit

Permalink
Merge branch 'release/0.3.2'
Browse files Browse the repository at this point in the history
* release/0.3.2:
  Feedback #2377 content RSS
  Feedback #2377 rss articlesj
  Feedback #2377 add RSS feed
  Esli Pasha hochet rasshirjaemost', to Pasha poluchit rasshirjaemost'
  fix  config #151
  add configuration for server mailer
  fix config
  fix with sender email
  • Loading branch information
kalashnikovisme committed Jul 16, 2015
2 parents 92a727f + a5e869b commit 79f6596
Show file tree
Hide file tree
Showing 27 changed files with 213 additions and 10 deletions.
9 changes: 9 additions & 0 deletions app/controllers/rss/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Rss::ApplicationController < ApplicationController
before_filter :set_rss_format

private

def set_rss_format
request.format = :xml
end
end
5 changes: 5 additions & 0 deletions app/controllers/rss/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Rss::ArticlesController < Rss::ApplicationController
def index
@articles = Article.broadcasted.decorate
end
end
7 changes: 7 additions & 0 deletions app/controllers/rss/content_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Rss::ContentController < Rss::ApplicationController
def index
articles = Article.broadcasted.decorate
news = News.published
@content = Kaminari.paginate_array (articles + news).sort_by{ |post| post.created_at }
end
end
5 changes: 5 additions & 0 deletions app/controllers/rss/news_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Rss::NewsController < Rss::ApplicationController
def index
@news = News.published.page params[:page]
end
end
2 changes: 1 addition & 1 deletion app/controllers/web/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create
else
if @user_form.save
#TODO replace to observers
#send_notification @user_form.model, @user_form.model, :after_create
send_notification @user_form.model, @user_form.model, :after_create

sign_in @user_form.model
redirect_to account_path
Expand Down
2 changes: 2 additions & 0 deletions app/decorators/article_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ def short_body
def name
title
end

alias :lead :short_body
end
22 changes: 22 additions & 0 deletions app/helpers/rss/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Rss::ApplicationHelper
def next_page
params[:page].present? ? page = params[:page].to_i + 1 : page = 2
send "#{params[:controller].gsub('/', '_')}_index_url", page: page
end

def header(xml)
xml.title t('.title')
xml.description t('.description')
xml.link root_url
xml.language 'ru'
xml.image do
xml.url 'http://ulmic.ru/assets/apps/logo-mic-square.png'
xml.width 100
xml.height 100
end
end

def rss_params
{ version: '2.0', 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', 'xmlns:ya' => 'http://blogs.yandex.ru/yarss/', 'xmlns:wfw' => 'http://wellformedweb.org/CommentAPI/' }
end
end
1 change: 1 addition & 0 deletions app/mailers/concerns/message_constructor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Concerns
module MessageConstructor

def create_message(type, theme)
messages_hash[type][theme]
end
Expand Down
1 change: 1 addition & 0 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ def just_message(user, message, subject)
@message = message
mail(to: user.email, subject: subject)
end

end
5 changes: 5 additions & 0 deletions app/models/news.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ class << self
transition :removed => :unviewed
end
end

def category
activity_line_tag = tags.activity_lines.first
activity_line_tag.target.title if activity_line_tag
end
end
1 change: 1 addition & 0 deletions app/scopes/article_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module ArticleScopes
scope :confirmed, -> { where(state: :confirmed).order('id DESC') }
scope :inactive, -> { where(state: :inactive).order('id DESC') }
scope :unviewed, -> { where(state: :unviewed).order('id DESC') }
scope :broadcasted, -> { where('category_id != ?', Category.find_by_name('Контакты').id) }
end
end
9 changes: 9 additions & 0 deletions app/views/rss/articles/_item.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
xml.item do
xml.guid article_url(item), isPermaLink: true
xml.author root_url
xml.pubDate item.created_at.to_s(:rfc822)
xml.link article_url(item)
xml.description item.lead
xml.title item.title
xml.category item.category.name
end
9 changes: 9 additions & 0 deletions app/views/rss/articles/index.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
xml.rss rss_params do
xml.channel do
header xml

for article in @articles
xml << render('item', xml: xml, item: article)
end
end
end
10 changes: 10 additions & 0 deletions app/views/rss/content/index.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
xml.rss rss_params do
xml.channel do
header xml

for post in @content
instance_name = post.model_name.name.underscore
xml << render("rss/#{instance_name.pluralize(:en)}/item", xml: xml, item: post)
end
end
end
10 changes: 10 additions & 0 deletions app/views/rss/news/_item.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
xml.item do
xml.guid news_url(item), isPermaLink: true
xml.author root_url
xml.pubDate item.published_at.to_s(:rfc822)
xml.link news_url(item)
xml.description item.lead
xml.title item.title
xml.category item.category
xml.tag! 'dc:creator', item.member.decorate.short_name
end
9 changes: 9 additions & 0 deletions app/views/rss/news/index.xml.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
xml.rss rss_params do
xml.channel do
header xml

for news in @news
xml<< render('item', xml: xml, item: news)
end
end
end
6 changes: 5 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = true
# output to tmp/mails directory
config.action_mailer.delivery_method = :sendmail
# ... and to specify output location
config.action_mailer.file_settings = { :location => Rails.root.join('tmp/mail') }

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
Expand Down
13 changes: 12 additions & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
Expand All @@ -28,7 +27,19 @@
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

config.action_mailer.raise_delivery_errors = true
# output to tmp/mails directory
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
# and to specify output location
config.action_mailer.file_settings = { :location => Rails.root.join('tmp/mail') }
# Do not fallback to assets pipeline if a precompiled asset is missed.

config.action_mailer.sendmail_settings = {
location: '/usr/sbin/sendmail',
arguments: '-i -t'
}

config.assets.compile = false

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
Expand Down
14 changes: 14 additions & 0 deletions config/locales/ru/rss.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ru:
rss:
news:
index:
title: Молодёжный инициативный центр
description: Новости Молодёжного инициативного центра
articles:
index:
title: Молодёжный инициативный центр
description: Статьи сайта Молодёжного инициативного центра
content:
index:
title: Молодёжный инициативный центр
description: Весь контент (новости, статьи) сайта Молодёжного инициативного центра
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
resources :tags, only: [ :create, :destroy, :index ]
end
end
namespace :rss do
resources :news, only: :index
resources :articles, only: :index
resources :content, only: :index
end
get '/:ticket' => 'web/members#show', constraints: { ticket: /\d*/ }, as: :member
get '*unmatched_route', to: 'web/pages#show', slug: :not_found
end
9 changes: 3 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@
t.text "title"
t.integer "member_id"
t.datetime "begin_date"
t.text "end_date", default: "for_now"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "end_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "tags", force: :cascade do |t|
Expand Down Expand Up @@ -238,9 +238,6 @@
t.integer "user_id"
end

add_index "teams_users", ["team_id"], name: "index_teams_users_on_team_id", using: :btree
add_index "teams_users", ["user_id"], name: "index_teams_users_on_user_id", using: :btree

create_table "users", force: :cascade do |t|
t.text "email"
t.text "password_digest"
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/rss/application_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class Rss::ApplicationControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
13 changes: 13 additions & 0 deletions test/controllers/rss/articles_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'test_helper'

class Rss::ArticlesControllerTest < ActionController::TestCase
setup do
create :user
@article = create :article
end

test 'should get index' do
get :index
assert_response :success, @response.body
end
end
15 changes: 15 additions & 0 deletions test/controllers/rss/content_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'test_helper'

class Rss::ContentControllerTest < ActionController::TestCase
setup do
create :user
create :member
create :article
create :news
end

test 'should get index' do
get :index
assert_response :success, @response.body
end
end
12 changes: 12 additions & 0 deletions test/controllers/rss/news_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'test_helper'

class Rss::NewsControllerTest < ActionController::TestCase
setup do
@news = create :news
end

test 'should get index' do
get :index
assert_response :success, @response.body
end
end
2 changes: 1 addition & 1 deletion test/factories/articles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
body { generate :string }
view nil
category_id { Category.first.id }
association :user
user_id { User.last ? User.last.id : 1 }
end

end
20 changes: 20 additions & 0 deletions test/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'
require 'redis'

class UserMailerTest < ActionMailer::TestCase
setup do
@user = create :user
end

test "check user email" do
Redis.new.ping
@user.generate_token

assert_emails 1 do
email = UserMailer.confirmation_instructions(@user).deliver_now
end
ap email
end


end

0 comments on commit 79f6596

Please sign in to comment.