Permalink
Browse files

posts, topics, forums tests, controllers, models, views

  • Loading branch information...
1 parent ac53773 commit ed054cb20e74f52fcace717d473acba4c4654cbf @isqad committed Apr 8, 2013
Showing with 16,060 additions and 28 deletions.
  1. +1 −1 Rakefile
  2. +1 −3 app/assets/javascripts/ruboard/application.js
  3. +2 −0 app/assets/javascripts/ruboard/forums.js
  4. +2 −0 app/assets/javascripts/ruboard/posts.js
  5. +2 −0 app/assets/javascripts/ruboard/topics.js
  6. +4 −0 app/assets/stylesheets/ruboard/forums.css
  7. +4 −0 app/assets/stylesheets/ruboard/posts.css
  8. +4 −0 app/assets/stylesheets/ruboard/topics.css
  9. +15 −0 app/controllers/ruboard/forums_controller.rb
  10. +6 −0 app/controllers/ruboard/posts_controller.rb
  11. +19 −0 app/controllers/ruboard/topics_controller.rb
  12. +6 −0 app/models/ruboard/forum.rb
  13. +8 −3 app/models/ruboard/post.rb
  14. +33 −2 app/models/ruboard/topic.rb
  15. +10 −0 app/models/ruboard/view.rb
  16. +3 −0 app/views/ruboard/forums/_forum.html.erb
  17. +3 −0 app/views/ruboard/forums/index.html.erb
  18. +3 −0 app/views/ruboard/forums/show.html.erb
  19. +10 −0 app/views/ruboard/posts/_list.html.erb
  20. +30 −0 app/views/ruboard/posts/_post.html.erb
  21. +13 −0 app/views/ruboard/topics/_list.html.erb
  22. +9 −0 app/views/ruboard/topics/_topic.html.erb
  23. +3 −0 app/views/ruboard/topics/show.html.erb
  24. +12 −0 config/locales/en.yml
  25. +20 −0 config/locales/ru.yml
  26. +5 −0 config/routes.rb
  27. +3 −0 db/migrate/20130317093433_create_ruboard_topics.rb
  28. +24 −0 db/migrate/20130408083406_create_ruboard_views.rb
  29. +14 −0 db/migrate/20130408103422_add_cache_counter_to_topics.rb
  30. +12 −2 lib/ruboard.rb
  31. +5 −0 ruboard.gemspec
  32. +19 −0 spec/controllers/ruboard/forums_controller_spec.rb
  33. +9 −0 spec/controllers/ruboard/posts_controller_spec.rb
  34. +11 −0 spec/controllers/ruboard/topics_controller_spec.rb
  35. +9 −0 spec/dummy/app/models/user.rb
  36. +7 −1 spec/dummy/config/application.rb
  37. +206 −0 spec/dummy/config/initializers/devise.rb
  38. +1 −0 spec/dummy/config/initializers/ruboard.rb
  39. +9 −0 spec/dummy/db/migrate/1_create_users.rb
  40. +3 −0 ...0130407170903_create_ruboard_topics.ruboard.rb → 20130408061320_create_ruboard_topics.ruboard.rb}
  41. +25 −0 spec/dummy/db/migrate/20130408085005_create_ruboard_views.ruboard.rb
  42. +15 −0 spec/dummy/db/migrate/20130408103824_add_cache_counter_to_topics.ruboard.rb
  43. +34 −7 spec/dummy/db/schema.rb
  44. +6,351 −0 spec/dummy/log/development.log
  45. +8,952 −0 spec/dummy/log/test.log
  46. +14 −3 spec/models/ruboard/post_spec.rb
  47. +65 −3 spec/models/ruboard/topic_spec.rb
  48. +18 −3 spec/spec_helper.rb
  49. +26 −0 spec/support/factories/factories.rb
View
@@ -1 +1 @@
-require "bundler/gem_tasks"
+require 'bundler/gem_tasks'
@@ -10,6 +10,4 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
-//= require jquery
-//= require jquery_ujs
-//= require_tree .
+//= require rails-timeago
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
+// Place all the behaviors and hooks related to the matching controller here.
+// All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
+/*
+ Place all the styles related to the matching controller here.
+ They will automatically be included in application.css.
+*/
@@ -0,0 +1,4 @@
+/*
+ Place all the styles related to the matching controller here.
+ They will automatically be included in application.css.
+*/
@@ -0,0 +1,4 @@
+/*
+ Place all the styles related to the matching controller here.
+ They will automatically be included in application.css.
+*/
@@ -0,0 +1,15 @@
+require_dependency 'ruboard/application_controller'
+
+module Ruboard
+ class ForumsController < Ruboard::ApplicationController
+
+ def index
+ @forums = Ruboard::Forum.with_topics
+ end
+
+ def show
+ @forum = Ruboard::Forum.with_topics.find(params[:id])
+ end
+
+ end
+end
@@ -0,0 +1,6 @@
+require_dependency "ruboard/application_controller"
+
+module Ruboard
+ class PostsController < ApplicationController
+ end
+end
@@ -0,0 +1,19 @@
+require_dependency 'ruboard/application_controller'
+
+module Ruboard
+ class TopicsController < Ruboard::ApplicationController
+
+ before_filter :find_forum
+
+ def show
+ @topic = @forum.topics.find(params[:id])
+ @posts = @topic.posts.includes(:user)
+ end
+
+ private
+ def find_forum
+ @forum = Ruboard::Forum.find(params[:forum_id])
+ end
+
+ end
+end
@@ -14,5 +14,11 @@ class Forum < ActiveRecord::Base
friendly_id :title, :use => :slugged
+ class << self
+ def with_topics
+ includes(:topics)
+ end
+ end
+
end
end
View
@@ -1,8 +1,13 @@
module Ruboard
class Post < ActiveRecord::Base
- attr_accessible :body, :user
- belongs_to :topic
- belongs_to :user
+ attr_accessible :body, :user, :body
+
+ belongs_to :topic, :counter_cache => true
+ belongs_to :user, :class_name => Ruboard.user_class.to_s
+
+ validates :body, :presence => true
+
+ delegate :name, :to => :user, :prefix => true, :allow_nil => true
end
end
@@ -1,9 +1,40 @@
+require 'friendly_id'
+
module Ruboard
class Topic < ActiveRecord::Base
+ extend FriendlyId
+
attr_accessible :title, :forum, :user
- has_many :posts, :dependent => :destroy
- belongs_to :user
+ has_many :posts, :dependent => :destroy, :order => 'ruboard_posts.created_at DESC'
+ has_many :views, :as => :viewable
+ belongs_to :user, :class_name => Ruboard.user_class.to_s
belongs_to :forum
+
+ validates :title, :presence => true, :length => { :minimum => 3, :maximum => 250 }
+
+ friendly_id :title, :use => :slugged
+
+ accepts_nested_attributes_for :posts
+
+ before_save :set_first_post_user
+
+ def register_view_by(user)
+ return unless user
+
+ view = self.views.find_or_create_by_user_id(user.id)
+ view.increment!(:count)
+ self.increment!(:views_count)
+ end
+
+ def view_for(user)
+ self.views.find_by_user_id(user.id)
+ end
+
+ private
+ def set_first_post_user
+ post = self.posts.first
+ post.user = self.user
+ end
end
end
View
@@ -0,0 +1,10 @@
+module Ruboard
+ class View < ActiveRecord::Base
+ attr_accessible :user, :count
+
+ belongs_to :user, :class_name => Ruboard.user_class.to_s
+ belongs_to :viewable, :polymorphic => true
+
+ validates :viewable_id, :viewable_type, :presence => true
+ end
+end
@@ -0,0 +1,3 @@
+<div class="ruboardForums__forum" id="forum_<%= forum.id %>">
+ <%= render 'ruboard/topics/list', :forum => forum %>
+</div>
@@ -0,0 +1,3 @@
+<div class="ruboardForums">
+ <%= render @forums %>
+</div>
@@ -0,0 +1,3 @@
+<div class="ruboardForums">
+ <%= render @forum %>
+</div>
@@ -0,0 +1,10 @@
+<table class="ruboardTopics__posts table table-bordered">
+ <thead>
+ <tr>
+ <th colspan="2" class="ruboardTopics__posts__title"><%= link_to topic.title, ruboard.forum_topic_path(forum, topic) %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <%= render posts, :forum => forum, :topic => topic %>
+ </tbody>
+</table>
@@ -0,0 +1,30 @@
+<tr>
+ <td><%= post.user_name %></td>
+ <td>
+ <div class="ruboardTopics__posts__info" id="post-<%= post.id %>">
+ <div class="ruboardTopics__posts__info__created">
+ <%= "#{t('activerecord.attributes.post.created_at')}: #{l(post.created_at, :format => :ruboard_full)}" %>
+ </div>
+ <div class="ruboardTopics__posts__info__number">
+ <%= link_to "##{post_counter + 1}", "#post-#{post.id}" %>
+ </div>
+ </div>
+ </td>
+</tr>
+<tr>
+ <td rowspan="3" class="ruboardTopics__posts__user">
+ Avatar
+ <p><%= t('ruboard.user.posts') %>: 0</p>
+ </td>
+</tr>
+<tr>
+ <td colspan="2">
+ <div class="ruboardTopics__posts__body">
+ <%= post.body %>
+ </div>
+ </td>
+</tr>
+<tr>
+ <td>Forum Sign</td>
+ <td>Menu</td>
+</tr>
@@ -0,0 +1,13 @@
+<table class="ruboardForums__topics table table-bordered">
+ <thead>
+ <tr>
+ <th colspan="2"><%= link_to forum.title, ruboard.forum_path(forum) %></th>
+ <th><%= t('activerecord.attributes.topic.answers') %></th>
+ <th><%= t('activerecord.attributes.topic.views') %></th>
+ <th><%= t('activerecord.attributes.topic.updates') %></th>
+ </tr>
+ </thead>
+ <tbody>
+ <%= render forum.topics, :forum => forum %>
+ </tbody>
+</table>
@@ -0,0 +1,9 @@
+<tr>
+ <td>Status</td>
+ <td>
+ <%= link_to topic.title, ruboard.forum_topic_path(forum, topic) %>
+ </td>
+ <td><%= topic.posts.size %></td>
+ <td><%= topic.views_count %></td>
+ <td><%= l(topic.updated_at, :format => :ruboard_full) %></td>
+</tr>
@@ -0,0 +1,3 @@
+<div class="ruboardTopics">
+ <%= render 'ruboard/posts/list', :topic => @topic, :forum => @forum, :posts => @posts %>
+</div>
View
@@ -0,0 +1,12 @@
+en:
+ activerecord:
+ models:
+ topic:
+ one: 'Topic'
+ other: 'Topics'
+ attributes:
+ topic:
+ title: 'Subject'
+ answers: 'Answers'
+ views: 'Views'
+ updates: 'Updates'
View
@@ -0,0 +1,20 @@
+ru:
+ activerecord:
+ models:
+ topic:
+ one: 'Тема'
+ few: 'Темы'
+ many: 'Тем'
+ other: 'Темы'
+ attributes:
+ topic:
+ title: 'Название'
+ answers: 'Ответов'
+ views: 'Просмотров'
+ updates: 'Обновления'
+ post:
+ body: 'Сообщение'
+ created_at: 'Отправлено'
+ time:
+ formats:
+ ruboard_full: '%d %B %Y %H:%M'
View
@@ -1,2 +1,7 @@
Ruboard::Engine.routes.draw do
+ root :to => 'forums#index'
+
+ resources :forums, :only => [ :index, :show ] do
+ resources :topics, :only => [ :show ]
+ end
end
@@ -1,15 +1,18 @@
class CreateRuboardTopics < ActiveRecord::Migration
def change
create_table :ruboard_topics do |t|
+ t.string :title, :null => false
t.integer :forum_id, :null => false
t.integer :user_id, :null => false
t.boolean :closed, :null => false, :default => false
t.boolean :pinned, :null => false, :default => false
+ t.string :slug
t.timestamps
end
add_index :ruboard_topics, :forum_id
add_index :ruboard_topics, :user_id
+ add_index :ruboard_topics, :slug, :unique => true
end
end
@@ -0,0 +1,24 @@
+class CreateRuboardViews < ActiveRecord::Migration
+ def self.up
+
+ add_column :ruboard_topics, :views_count, :integer, :default => 0
+
+ create_table :ruboard_views do |t|
+ t.integer :user_id
+ t.integer :viewable_id
+ t.string :viewable_type
+ t.datetime :current_viewed_at
+ t.datetime :past_viewed_at
+ t.integer :count, :default => 0
+ t.timestamps
+ end
+
+ add_index :ruboard_views, [:viewable_id, :viewable_type], :name => 'ruboard_views_viewable_idx'
+ add_index :ruboard_views, :user_id
+ end
+
+ def self.down
+ remove_column :ruboard_topics, :views_count
+ drop_table :ruboard_views
+ end
+end
@@ -0,0 +1,14 @@
+class AddCacheCounterToTopics < ActiveRecord::Migration
+ def self.up
+ add_column :ruboard_topics, :posts_count, :integer, :default => 0
+
+ Ruboard::Topic.reset_column_information
+ Ruboard::Topic.find_each do |t|
+ Ruboard::Topic.update_counters t.id, :posts_count => t.posts.length
+ end
+ end
+
+ def self.down
+ remove_column :ruboard_topics, :posts_count
+ end
+end
View
@@ -1,6 +1,16 @@
-require "ruboard/version"
+require 'ruboard/version'
require 'ruboard/engine'
module Ruboard
- # Your code goes here...
+ mattr_accessor :user_class
+
+ class << self
+ def user_class
+ begin
+ Object.const_get(@@user_class)
+ rescue NameError
+ @@user_class.constantize
+ end
+ end
+ end
end
View
@@ -19,7 +19,12 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rspec-rails', '~> 2.6'
gem.add_development_dependency 'factory_girl_rails', '~> 1.7'
+ gem.add_development_dependency 'database_cleaner'
+ gem.add_development_dependency 'devise'
+ gem.add_development_dependency 'jquery-rails'
+ gem.add_development_dependency 'russian'
gem.add_dependency 'rails', ['>= 3.1.10', '< 3.3'] | 0.upto(10).map{|i| "!= 3.2.#{i}"}
gem.add_dependency 'friendly_id', '~> 4.0', '>= 4.0.9'
+ gem.add_dependency 'rails-timeago', '~> 2.0'
end
Oops, something went wrong.

0 comments on commit ed054cb

Please sign in to comment.