Month: June 2017

Build a TDD RESTful JSON TODO-List API (pt.3)

Next on our list: controller. class TodosController < ApplicationController before_action :set_todo, only: [:show, :update, :destroy] # GET /todos def index @todos = Todo.all json_response(@todos) end # POST /todos def create @todo = Todo.create!(todo_params) json_response(@todo, :created) end # GET /todos/:id def show json_response(@todo) end # PUT /todos/:id def update @todo.update(todo_params) head :no_content end # DELETE /todos/:id … Continue reading Build a TDD RESTful JSON TODO-List API (pt.3)

Advertisements

Build a TDD RESTful JSON TODO-List API (pt.2)

Fixing the failures   ...by editing our two models: /app/models/todo.rb # app/models/todo.rb class Todo < ApplicationRecord # model association has_many :items, dependent: :destroy # validations validates_presence_of :title, :created_by end app/models/item.rb class Item < ApplicationRecord belongs_to :todo # validation validates_presence_of :name end running bundle exec rspec again will result in 0 errors as expected: Finished in … Continue reading Build a TDD RESTful JSON TODO-List API (pt.2)