Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from johnf/master

Some small fixes around validations and errors
  • Loading branch information...
commit 04dff64ef6dbd4605c31ba9d8c7ba84cb07e339d 2 parents e201e89 + 7388f07
@Draiken authored
View
20 app/views/opinio/comments/create.js.erb
@@ -1,11 +1,15 @@
$('#no_comments').fadeOut()
-<% if @reply %>
- if($('#comment_<%= @comment.commentable_id %> ul').length == 0)
- $('#comment_<%= @comment.commentable_id %>').append('<ul id="comment_<%= @comment.commentable_id %>_replies" class="replies"></ul>')
- $('#comment_<%= @comment.commentable_id %>_replies').append("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
- $('#commentable_id').val('<%= @comment.commentable.commentable_id %>')
- $('#commentable_type').val('<%= @comment.commentable.commentable_type %>')
+<% if @comment.valid? %>
+ <% if @reply %>
+ if($('#comment_<%= @comment.commentable_id %> ul').length == 0)
+ $('#comment_<%= @comment.commentable_id %>').append('<ul id="comment_<%= @comment.commentable_id %>_replies" class="replies"></ul>')
+ $('#comment_<%= @comment.commentable_id %>_replies').append("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
+ $('#commentable_id').val('<%= @comment.commentable.commentable_id %>')
+ $('#commentable_type').val('<%= @comment.commentable.commentable_type %>')
+ <% else %>
+ $('#comments').prepend("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
+ <% end %>
<% else %>
- $('#comments').prepend("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
+ jQuery('#comments').prepend("<%= escape_javascript(flash[:notice]) %>");
+ jQuery('#comments').prepend("<%= escape_javascript(flash[:error]) %>");
<% end %>
-
View
2  lib/opinio/opinio_model.rb
@@ -61,6 +61,8 @@ def opinio(*args)
validates_presence_of :commentable
+ validates :owner, :presence => true, :associated => true
+
scope :owned_by, lambda {|owner| where('owner_id = ?', owner.id) }
send :include, Opinio::OpinioModel::InstanceMethods
View
6 lib/opinio/shared_examples.rb
@@ -39,6 +39,12 @@
comment.errors[:commentable].should be_present
end
+ it "and it should insist on having an owner" do
+ c = Comment.new(:body => "The Comment !")
+ c.commentable = @post
+ c.save.should == false
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.