I have two models, Sector e Category. Category has_many :sectors. I use database_cleaner e rspec call it through this file: RSpec.configure do |config| config.before :suite do DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with :truncation end config.before :each do DatabaseCleaner.start end config.after :each do DatabaseCleaner.clean end end The test for model Sector is: describe Sector do before(:each) do @attr = { :name => "Sector-1" } end it "should create a new instance given valid attributes" do Sector.create!(@attr) end it "should require a name" do no_name_sector = Sector.new(@attr.merge(:name => "")) no_name_sector.should_not be_valid end end It passes and the db is cleaned. The test for Category is: describe Category do before(:each) do sector = Sector.make! @attr = { :name => "Category-1", :sector => sector} end it "should create a new instance given valid attributes" do Category.create!(@attr) end it "should require a name" do no_name_category = Category.new(@attr.merge(:name => "")) no_name_category.should_not be_valid end it "should require a Sector" do no_sector_category = Category.new(@attr.merge(:sector => nil)) no_sector_category.should_not be_valid end end Also this test passes but the db is not cleaned and I have 3 Sectors. Do you know why the db is not cleaned when I run Category test? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Try posting a bit of the test.log to seed what is happening to the db -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
REMOVE ME -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 June 2011 17:15, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Try posting a bit of the test.log to seed what is happening to the dbSorry I''ve found that the problem is when I run autotest. If I run rspec individually for every controller they passes. If I run autotest they don''t pass. For sector controller test I''ve posted the code, if I run rspec for it passes. If I run autotest it says: SectorsController GET index assigns all sectors as @sectors Failure/Error: assigns(:sectors).should eq([sector]) expected [#<Sector id: 2603, name: "Sector-1", created_at: "2011-06-02 18:20:15", updated_at: "2011-06-02 18:20:15">] got [#<Sector id: 2548, name: "Sector-1", created_at: "2011-06-02 18:19:46", updated_at: "2011-06-02 18:19:46">, #<Sector id: 2549, name: "Sector-1", created_at: "2011-06-02 18:19:46", updated_at: "2011-06-02 18:19:46">, #<Sector id: 2550 etc. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Jun 2, 2011 at 10:58 AM, Brian <railsml-nXY6sOM8F3RqvOwRj+kr0A@public.gmane.org> wrote:> REMOVE ME > >To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 June 2011 18:25, Mauro <mrsanna1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2 June 2011 17:15, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Try posting a bit of the test.log to seed what is happening to the db > > Sorry I''ve found that the problem is when I run autotest. > If I run rspec individually for every controller they passes. > If I run autotest they don''t pass. > For sector controller test I''ve posted the code, if I run rspec for it passes. > If I run autotest it says: > > SectorsController GET index assigns all sectors as @sectors > Failure/Error: assigns(:sectors).should eq([sector]) > > expected [#<Sector id: 2603, name: "Sector-1", created_at: > "2011-06-02 18:20:15", updated_at: "2011-06-02 18:20:15">] > got [#<Sector id: 2548, name: "Sector-1", created_at: > "2011-06-02 18:19:46", updated_at: "2011-06-02 18:19:46">, #<Sector > id: 2549, name: "Sector-1", created_at: "2011-06-02 18:19:46", > updated_at: "2011-06-02 18:19:46">, #<Sector id: 2550In the configuration of database_cleaner I''ve changed DatabaseCleaner.strategy = :transaction to DatabaseCleaner.strategy :deletion and when I run autotest now the tests pass. I''ve to use DatabaseCleaner.strategy = :transaction when I run rspec individually for every spec and DatabaseCleaner.strategy = :deletion when I run autotest? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
+1 Conrad On Thu, Jun 2, 2011 at 12:06 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 2, 2011 at 10:58 AM, Brian <railsml-nXY6sOM8F3RqvOwRj+kr0A@public.gmane.org> wrote: > >> REMOVE ME >> >> > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Careful what ask for :) On Thu, Jun 2, 2011 at 2:16 PM, Jatin kumar <jatinkumar.nitk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> +1 Conrad > > > On Thu, Jun 2, 2011 at 12:06 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> On Thu, Jun 2, 2011 at 10:58 AM, Brian <railsml-nXY6sOM8F3RqvOwRj+kr0A@public.gmane.org> wrote: >> >>> REMOVE ME >>> >>> >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.