Skip to content

Commit

Permalink
Merge 1259647 into 6edcd18
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxSchneider1337 committed Nov 15, 2018
2 parents 6edcd18 + 1259647 commit 6300cf3
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ def set_request

# Never trust parameters from the scary internet, only allow the white list through.
def request_params
params.require(:request).permit(:operating_system, :ram_mb, :cpu_cores, :software, :comment, :accepted)
params.require(:request).permit(:operating_system, :ram_mb, :cpu_cores, :software, :comment, :rejection_information, :status)
end
end
2 changes: 2 additions & 0 deletions app/helpers/requests_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module RequestsHelper
end
3 changes: 3 additions & 0 deletions app/models/request.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# frozen_string_literal: true

class Request < ApplicationRecord
enum status: %i[pending accepted rejected]
end
5 changes: 0 additions & 5 deletions app/views/requests/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<%= form.text_field :comment %>
</div>

<div class="field">
<%= form.label :accepted %>
<%= form.check_box :accepted %>
</div>

<div class="actions">
<%= form.submit %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/requests/_request.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
json.extract! request, :id, :operating_system, :ram_mb, :cpu_cores, :software, :comment, :accepted, :created_at, :updated_at
json.extract! request, :id, :operating_system, :ram_mb, :cpu_cores, :software, :comment, :rejection_information, :status, :created_at, :updated_at
json.url request_url(request, format: :json)
9 changes: 5 additions & 4 deletions app/views/requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<thead>
<tr>
<th>Operating system</th>
<th>Ram mb</th>
<th>Cpu cores</th>
<th>MB RAM</th>
<th>Cpu-Cores</th>
<th>Software</th>
<th>Accepted</th>
<th>Comment</th>
<th>Status </th>
<th colspan="3"></th>
</tr>
</thead>
Expand All @@ -22,7 +23,7 @@
<td><%= request.cpu_cores %></td>
<td><%= request.software %></td>
<td><%= request.comment %></td>
<td><%= request.accepted %></td>
<td><%= request.status %></td>
<td><%= link_to 'Show', request %></td>
<td><%= link_to 'Edit', edit_request_path(request) %></td>
<td><%= link_to 'Destroy', request, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down
32 changes: 30 additions & 2 deletions app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,37 @@
</p>

<p>
<strong>Accepted:</strong>
<%= @request.accepted %>
<strong>Status:</strong>
<%= @request.status %>
</p>

<% if @request.rejected? %>
<p>
<strong>Rejection Information:</strong>
<%= @request.rejection_information %>
</p>
<% end %>
<% if @request.pending? %>
<%= form_with(model: @request, local: true) do |form| %>
<div class="actions">
<%= form.hidden_field :status, value: 'accepted' %>
<%= form.submit 'Accept' %>
</div>
<% end %>
<%= form_with(model: @request, local: true) do |form| %>
<div class="field">
<%= form.label :rejection_information %>
<%= form.text_field :rejection_information %>
</div>

<div class="actions">
<%= form.hidden_field :status, value: 'rejected' %>
<%= form.submit 'Reject' %>
</div>
<% end %>
<% end %>
<%= link_to 'Edit', edit_request_path(@request) %> |
<%= link_to 'Back', requests_path %>
3 changes: 2 additions & 1 deletion db/migrate/20181113194553_create_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def change
t.integer :cpu_cores
t.string :software
t.text :comment
t.boolean :accepted
t.text :rejection_information
t.integer :status, default: 0

t.timestamps
end
Expand Down
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
t.integer "cpu_cores"
t.string "software"
t.text "comment"
t.boolean "accepted"
t.text "rejection_information"
t.integer "status", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down
8 changes: 6 additions & 2 deletions spec/factories/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
ram_mb { 1 }
cpu_cores { 1 }
software { 'MyString' }
comment { 'MyString' }
accepted { false }
comment { 'Comment' }
status { 'pending' }
end
factory :rejected_request, parent: :request do
status { 'rejected' }
rejection_information { 'Info' }
end
end
5 changes: 1 addition & 4 deletions spec/views/requests/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
cpu_cores: 1,
software: 'MyString',
comment: 'MyString',
accepted: false
status: 'pending'
))
end

it 'renders the edit request form' do
render

assert_select 'form[action=?][method=?]', request_path(@request), 'post' do

assert_select 'input[name=?]', 'request[operating_system]'

assert_select 'input[name=?]', 'request[ram_mb]'
Expand All @@ -28,8 +27,6 @@
assert_select 'input[name=?]', 'request[software]'

assert_select 'input[name=?]', 'request[comment]'

assert_select 'input[name=?]', 'request[accepted]'
end
end
end
6 changes: 3 additions & 3 deletions spec/views/requests/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
cpu_cores: 3,
software: 'Software',
comment: 'Comment',
accepted: false
status: 'pending'
),
Request.create!(
operating_system: 'Operating System',
ram_mb: 2,
cpu_cores: 3,
software: 'Software',
comment: 'Comment',
accepted: false
status: 'pending'
)
])
end
Expand All @@ -31,6 +31,6 @@
assert_select 'tr>td', text: 3.to_s, count: 2
assert_select 'tr>td', text: 'Software'.to_s, count: 2
assert_select 'tr>td', text: 'Comment'.to_s, count: 2
assert_select 'tr>td', text: false.to_s, count: 2
assert_select 'tr>td', text: 'pending'.to_s, count: 2
end
end
5 changes: 1 addition & 4 deletions spec/views/requests/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
cpu_cores: 1,
software: 'MyString',
comment: 'Comment',
accepted: false
status: 'pending'
))
end

it 'renders new request form' do
render

assert_select 'form[action=?][method=?]', requests_path, 'post' do

assert_select 'input[name=?]', 'request[operating_system]'

assert_select 'input[name=?]', 'request[ram_mb]'
Expand All @@ -28,8 +27,6 @@
assert_select 'input[name=?]', 'request[software]'

assert_select 'input[name=?]', 'request[comment]'

assert_select 'input[name=?]', 'request[accepted]'
end
end
end
65 changes: 47 additions & 18 deletions spec/views/requests/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,53 @@
require 'rails_helper'

RSpec.describe 'requests/show', type: :view do
before(:each) do
@request = assign(:request, Request.create!(
operating_system: 'Operating System',
ram_mb: 2,
cpu_cores: 3,
software: 'Software',
comment: 'Comment',
accepted: false
))
RSpec.describe 'requests/show', type: :feature do
context 'when request status is pending' do
let(:request) { FactoryBot.create :request }

it 'renders attributes in <p>' do
visit request_path(request)

expect(page).to have_text(request.operating_system)
expect(page).to have_text(request.ram_mb)
expect(page).to have_text(request.cpu_cores)
expect(page).to have_text(request.software)
expect(page).to have_text(request.status)
expect(page).to have_text(request.comment)
end

it 'has accept button' do
visit request_path(request)

click_button('Accept')
request.reload
expect(request.status).to eq('accepted')
end

it 'has reject button' do
visit request_path(request)

click_button('Reject')
request.reload
expect(request.status).to eq('rejected')
end

it 'has rejection_information input field' do
visit request_path(request)

page.fill_in 'request[rejection_information]', with: 'Info'
click_button('Reject')
request.reload
expect(request.rejection_information).to eq('Info')
end
end

it 'renders attributes in <p>' do
render
expect(rendered).to match(/Operating System/)
expect(rendered).to match(/2/)
expect(rendered).to match(/3/)
expect(rendered).to match(/Software/)
expect(rendered).to match(/Comment/)
expect(rendered).to match(/false/)
context 'when request is rejected' do
let(:rejected_request) { FactoryBot.create :rejected_request }

it 'Has rejection Information field' do
visit request_path(rejected_request)

expect(page).to have_text(rejected_request.rejection_information)
end
end
end

0 comments on commit 6300cf3

Please sign in to comment.