-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* | ||
Place all the styles related to the matching controller here. | ||
They will automatically be included in application.css. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class PlansController < ApplicationController | ||
before_action :set_plan, only: [:show] | ||
|
||
# GET /plans | ||
# GET /plans.json | ||
def index | ||
@plans = Plan.all | ||
end | ||
|
||
# GET /plans/1 | ||
# GET /plans/1.json | ||
def show; end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_plan | ||
@plan = Plan.find(params[:id]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module PlansHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! plan, :id, :created_at, :updated_at | ||
json.url plan_url(plan, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1>Plans</h1> | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
<th colspan="3"></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @plans.each do |plan| %> | ||
<tr> | ||
<td><%= plan.name %></td> | ||
<td><%= plan.description %></td> | ||
<td>$<%= plan.amount %></td> | ||
<td><%= link_to 'Show', plan %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @plans, partial: "plans/plan", as: :plan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
<h1><%= @plan.name %></h1> | ||
<p><%= @plan.description %></p> | ||
<p>$<%= @plan.amount %></p> | ||
|
||
<%= link_to 'Back', plans_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "plans/plan", plan: @plan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe PlansController, type: :controller do | ||
let(:valid_attributes) do | ||
FactoryBot.attributes_for(:plan) | ||
end | ||
|
||
let(:valid_session) { {} } | ||
|
||
describe 'GET #index' do | ||
it 'returns a success response' do | ||
Plan.create! valid_attributes | ||
get :index, params: {}, session: valid_session | ||
expect(response).to be_successful | ||
end | ||
end | ||
|
||
describe 'GET #show' do | ||
it 'returns a success response' do | ||
plan = Plan.create! valid_attributes | ||
get :show, params: { id: plan.to_param }, session: valid_session | ||
expect(response).to be_successful | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe PlansController, type: :routing do | ||
describe 'routing' do | ||
it 'routes to #index' do | ||
expect(get: '/plans').to route_to('plans#index') | ||
end | ||
|
||
it 'routes to #show' do | ||
expect(get: '/plans/1').to route_to('plans#show', id: '1') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'plans/index', type: :view do | ||
let(:plan_1) { FactoryBot.attributes_for(:plan) } | ||
let(:plan_2) { FactoryBot.attributes_for(:plan) } | ||
|
||
before(:each) do | ||
assign(:plans, [ | ||
Plan.create!(plan_1), | ||
Plan.create!(plan_2) | ||
]) | ||
end | ||
|
||
it 'renders a list of plans' do | ||
render | ||
assert_select 'tr>td', text: plan_1[:name].to_s | ||
assert_select 'tr>td', text: plan_2[:name].to_s | ||
|
||
assert_select 'tr>td', text: plan_1[:description].to_s | ||
assert_select 'tr>td', text: plan_2[:description].to_s | ||
|
||
assert_select 'tr>td', text: "$#{plan_1[:amount]}" | ||
assert_select 'tr>td', text: "$#{plan_2[:amount]}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'plans/show', type: :view do | ||
let(:plan) { FactoryBot.attributes_for(:plan) } | ||
|
||
before(:each) do | ||
@plan = assign(:plan, Plan.create!(plan)) | ||
end | ||
|
||
it 'renders attributes' do | ||
render | ||
expect(rendered).to match(/#{plan[:name]}/) | ||
expect(rendered).to match(/#{plan[:description]}/) | ||
expect(rendered).to match(/\$#{plan[:amount]}/) | ||
end | ||
end |