spec/unit/comments_spec.rb in activeadmin-1.0.0.pre1 vs spec/unit/comments_spec.rb in activeadmin-1.0.0.pre2
- old
+ new
@@ -27,22 +27,24 @@
it "should return a comment for the resource in the same namespace" do
expect(ActiveAdmin::Comment.find_for_resource_in_namespace(post, namespace_name)).to eq [@comment]
end
it "should not return a comment for the same resource in a different namespace" do
+ ActiveAdmin.application.namespaces[:public] = ActiveAdmin.application.namespaces[:admin]
expect(ActiveAdmin::Comment.find_for_resource_in_namespace(post, 'public')).to eq []
+ ActiveAdmin.application.namespaces.instance_variable_get(:@namespaces).delete(:public)
end
it "should not return a comment for a different resource" do
another_post = Post.create! title: "Another Hello World"
expect(ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name)).to eq []
end
it "should return the most recent comment first" do
ActiveAdmin::Comment.class_eval { attr_accessible :created_at } if Rails::VERSION::MAJOR == 3
- another_comment = ActiveAdmin::Comment.create! resource: post,
- body: "Another Comment",
+ another_comment = ActiveAdmin::Comment.create! resource: post,
+ body: "Another Comment",
namespace: namespace_name,
created_at: @comment.created_at + 20.minutes
yet_another_comment = ActiveAdmin::Comment.create! resource: post,
body: "Yet Another Comment",
@@ -52,9 +54,29 @@
comments = ActiveAdmin::Comment.find_for_resource_in_namespace(post, namespace_name)
expect(comments.size).to eq 3
expect(comments.first).to eq(@comment)
expect(comments.second).to eq(yet_another_comment)
expect(comments.last).to eq(another_comment)
+ end
+
+ it "should return the correctly ordered comments" do
+ ActiveAdmin::Application.inheritable_setting(
+ :comments_order, "created_at DESC"
+ )
+
+ another_comment = ActiveAdmin::Comment.create!(
+ resource: post,
+ body: "Another Comment",
+ namespace: namespace_name,
+ created_at: @comment.created_at + 20.minutes
+ )
+
+ comments = ActiveAdmin::Comment.find_for_resource_in_namespace(
+ post, namespace_name
+ )
+ expect(comments.size).to eq 2
+ expect(comments.first).to eq(another_comment)
+ expect(comments.last).to eq(@comment)
end
end
describe ".resource_id_cast" do
let(:post) { Post.create!(title: "Testing.") }