Posts

Setup Rspec

 1 install following Gems       group :development, :test do          # Use for test application        gem 'rspec-rails', '~> 5.0.2'        # Use for fixtures        gem 'factory_bot_rails', '~> 5.2.0'        # For create fake data        gem 'faker', '~> 2.19.0'        # use assigns in controller rspec        gem 'rails-controller-testing'   end             bundle install       rails generate rspec:install       bundle exec rspec           2 Format Spec output on console      add below line in  spec/.rspec file (create new file .rspec)       --format documentation            3 Modal Test cases  ...

Comparison between &&= and ||=

&&=    ||= Example 1 x=5 x=5 y=7 y=7 x&&=y x||=y X=7 x=5 y=7 y=7 Example 2 x=nil x=nil y=7 y=7 x&&=y x||=y x=nil x=5 y=7 y=7 Example 3 x=5 x=5 y=nil y=nil x&&=y x||=y x=nil x=5 y=nil y=nil

Difference between was, before_last_save, changed and changed?

  was: in the update action before update record if you want previous price not updated price then you should use @product.price_was before_last_save:   in the update action after update record if you want previous price not updated price then you should use @product.price_before_last_save changed?:   if you want to check your object is update or not? OR any value of object is updated or not then user this function.(Eg. @product.changed?) changed: if you want to check  what fields is updated  (Eg. @product.changed)

Standard of Code Sequence of model

 class Model < ActiveRecord::Base    #all mixins    include Something    extend Something     #other stuff    acts_as_taggable    paginates     #associations    has_many :something    belongs_to :something_else     #validations    validate_presence_of :something     #scopes    scope :something     #instance methods    def instance_method    end     #class methods    def self.method    end     #private methods    private    def method2    end End