Sha256: ab0f563c87bd4fb35c56a70de093ce50112ab5d5966bde6b5ddc75b231a85614

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../spec_helper')

describe RailsBestPractices::Checks::UseObserverCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::UseObserverCheck.new)
  end

  it "should use observer" do
    content =<<-EOF
    class Project < ActiveRecord::Base
      after_create :send_create_notification

      private

      def send_create_notification
        self.members.each do |member|
          ProjectMailer.deliver_notification(self, member)
        end
      end
    end
    EOF
    @runner.check('app/models/project.rb', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/models/project.rb:6 - use observer"
  end

  it "should not use observer without callback" do
    content =<<-EOF
    class Project < ActiveRecord::Base
      private

      def send_create_notification
        self.members.each do |member|
          ProjectMailer.deliver_notification(self, member)
        end
      end
    end
    EOF
    @runner.check('app/models/project.rb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_best_practices-0.2.5 spec/rails_best_practices/checks/use_observer_check_spec.rb
rails_best_practices-0.2.4 spec/rails_best_practices/checks/use_observer_check_spec.rb
rails_best_practices-0.2.3 spec/rails_best_practices/checks/use_observer_check_spec.rb