Permalink
Browse files

Added regression spec for a belongs_to association with :group_by => …

…:author
  • Loading branch information...
1 parent 7a2ef48 commit 9c1daba14daea0d56d309d64322b87d570af832c Jacob Kjeldahl committed with Nov 25, 2009
Showing with 21 additions and 1 deletion.
  1. +11 −0 spec/inputs/select_input_spec.rb
  2. +10 −1 spec/spec_helper.rb
@@ -103,6 +103,17 @@
end
end
+ describe "for a belongs_to association with :group_by => :author" do
+ it "should call author.posts" do
+ [@freds_post].each { |post| post.stub!(:to_label).and_return("Post - #{post.id}") }
+ @fred.should_receive(:posts)
+
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:main_post, :as => :select, :group_by => :author ) )
+ end
+ end
+ end
+
describe 'for a belongs_to association with :group_by => :continent' do
before do
@authors = [@bob, @fred, @fred, @fred]
View
@@ -124,6 +124,8 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:new_record?).and_return(true)
@new_post.stub!(:errors).and_return(mock('errors', :[] => nil))
@new_post.stub!(:author).and_return(nil)
+ @new_post.stub!(:main_post).and_return(nil)
+ @new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
@freds_post = mock('post')
@freds_post.stub!(:class).and_return(::Post)
@@ -150,7 +152,12 @@ def new_author_path; "/authors/new"; end
mock
when :authors
mock('reflection', :options => {}, :klass => ::Author, :macro => :has_and_belongs_to_many)
+ when :sub_posts
+ mock('reflection', :options => {}, :klass => ::Post, :macro => :has_many)
+ when :main_post
+ mock('reflection', :options => {}, :klass => ::Post, :macro => :belongs_to)
end
+
end
::Post.stub!(:find).and_return([@freds_post])
::Post.stub!(:content_columns).and_return([mock('column', :name => 'title'), mock('column', :name => 'body'), mock('column', :name => 'created_at')])
@@ -174,9 +181,11 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:author).and_return(@bob)
@new_post.stub!(:author_id).and_return(@bob.id)
-
+
@new_post.should_receive(:publish_at=).any_number_of_times
@new_post.should_receive(:title=).any_number_of_times
+ @new_post.stub!(:main_post_id).and_return(nil)
+
end
def self.included(base)

0 comments on commit 9c1daba

Please sign in to comment.