Skip to content
Browse files

Merge branch 'master' of github.com:makevoid/sinforum into bit

  • Loading branch information...
2 parents 1b3eb96 + 626f445 commit 8b8409e41074c0c516045272bae26b7ffb749759 @makevoid committed
View
5 exts/auth/models/user.rb
@@ -25,9 +25,10 @@ class User
# attributes
+ DEFAULT_AVATAR = "/images/avatars/d3_1.jpg"
+
def avatar_image
- default_avatar = "/images/avatars/d3_1.jpg"
- "<img src='#{avatar.nilblank || default_avatar}' class='avatar' />"
+ "<img src='#{avatar.nilblank || DEFAULT_AVATAR}' class='avatar' />"
end
View
18 models/post.rb
@@ -13,6 +13,16 @@ class Post
validates_presence_of :title, :if => lambda { |p| p.parent_id.nil? }
+ # scopes
+
+ def self.by_update
+ all order: :updated_at.desc
+ end
+
+ def self.roots
+ all parent_id: nil
+ end
+
# parent
property :parent_id, Integer
@@ -43,7 +53,13 @@ def children
end
after :save do
- forum.update updated_at: Time.now, last_post_id: self.id, posts_count: forum.posts_count+1 if root?
+ attrs = { updated_at: Time.now }
+ if root?
+ attrs.merge! last_post_id: self.id, posts_count: forum.posts_count+1
+ else
+ parent.update attrs
+ end
+ forum.update attrs
end
after :destroy do
View
BIN public/images/sinforum.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
2 routes/forums.rb
@@ -14,7 +14,7 @@ class Sinforum < Sinatra::Base
get "/forums/:id" do |id|
@forum = Forum.get id
member_required if @forum.private?
- @posts = @forum.posts.all(parent_id: nil)
+ @posts = @forum.posts.roots.by_update
haml :forum
end
View
2 spec/acceptance/forums_spec.rb
@@ -3,6 +3,7 @@
describe "Forum" do
let(:forum){ Forum.create name: "foro" }
let(:post1){ forum.posts.create title: "one", text: "one", user_id: user.id }
+ let(:post2){ forum.posts.create title: "oneB", text: "oneB", user_id: user.id }
let(:forum_pvt){ Forum.create name: "secreeto", private: true }
before :all do
@@ -17,6 +18,7 @@
it "GET /forums/:id" do
get "/forums/#{forum.id}"
body.should include(forum.name)
+ # body.should include(post2.title)
end
context "private forums - as guest" do
View
6 views/layout.haml
@@ -5,6 +5,12 @@
%link{ rel: "stylesheet", href: "/css/main.css" }
%script{ type: "text/javascript", src: "/js/vendor/zepto.js" }
%script{ type: "text/javascript", src: "/js/main.js" }
+ %meta{ property: "og:title", content: "Sinforum" }
+ %meta{ property: "og:url", content: "http://example.com" }/
+ %meta{ property: "og:type", content: "website" }/
+ %meta{ property: "og:site_name", content: "Sinforum" }/
+ %meta{ property: "og:image", content: "/images/sinforum.png" }/
+ %meta{ property: "fb:admins", content: "makevoid" }/
%body
#container
%header
View
6 views/post.haml
@@ -7,7 +7,11 @@
- @replies.each do |reply|
= partial :post_full, reply
-- link_to "Reply", "javascript:void(0)", class: "reply_btn btn"
+- if logged?
+ - link_to "Reply", "javascript:void(0)", class: "reply_btn btn"
+- else
+ - link_to "Login", "/login"
+ to reply
.reply
- @reply = Post.new params[:post]

0 comments on commit 8b8409e

Please sign in to comment.
Something went wrong with that request. Please try again.