#TDD
before_action :find_question, only:[:show, :edit, :update, :destroy] before_action :find_question, except:[:new, :create, index]
this will call find_question action before all the other action
def before_action
@question = Question.find params[:id]
endNow we can delete al the @question = Question.find params[:id] lines
We can define part of erb file as a partial by using underline infront of the file name
_form.html.erb
after copying the comman code inside of other erb files place it on _form.html.erb file
afterwards replace the comman code with this
<%= render "form" %>
you can even pass an local variable in a hash
<%= render "form", my_var: my_variable %>
to display a message to the user for a short time
flash[:notice] = "Question Created Successfully"
afterwards write the code <%= notice %>
in the view, layout page
flash[:alert] = "Question was not created. Check errors below
<%= notice || alert %>
for redirect_ to
notice: "Question updated!"
notice: "Question deleted!"
Given..When..Then..
Given --------> no question in DB existing question in DB
When ----------> create question with same title
Then ----------> no question created in the DB
Ruby motion
rspec-rails
rails new fundsy -T -d postgresql
bin/rails generate rspec:install
bin/rake db:create RAILS_ENV=test
bin/rails g
bin/rails g rspec:model campaign
bin/rails g model campaign name description:text goal:integer end_date:datetime
for delete
bin/rails d model campaign name description:text goal:integer end_date:datetime
in your model
validates :name, presence: true
rspec spec/controllers/campaigns_controller_spec.rb:5
resources :campaigns, only: [:new]