weeks in progress
This commit is contained in:
parent
5a1c285989
commit
25f09a3515
|
|
@ -76,7 +76,7 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def collection
|
def collection
|
||||||
@courses = Course.all
|
@courses = Course.by_name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin
|
||||||
|
# Kursy
|
||||||
|
class WeeksController < ApplicationController
|
||||||
|
before_action :set_object, only: %i[show edit update destroy]
|
||||||
|
|
||||||
|
# GET /admin/weeks
|
||||||
|
# GET /admin/weeks.json
|
||||||
|
def index
|
||||||
|
collection
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /admin/weeks/1
|
||||||
|
# GET /admin/weeks/1.json
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
# GET /admin/weeks/new
|
||||||
|
def new
|
||||||
|
@week = Week.new(course_id: params[:course_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /admin/weeks/1/edit
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
# POST /admin/weeks
|
||||||
|
# POST /admin/weeks.json
|
||||||
|
def create
|
||||||
|
@week = Week.new(admin_week_params)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @week.save
|
||||||
|
format.js { collection }
|
||||||
|
format.html { redirect_to [:admin, @week], notice: 'Week was successfully created.' }
|
||||||
|
format.json { render :show, status: :created, location: @week }
|
||||||
|
else
|
||||||
|
format.js { render :new }
|
||||||
|
format.html { render :new }
|
||||||
|
format.json { render json: @week.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PATCH/PUT /admin/weeks/1
|
||||||
|
# PATCH/PUT /admin/weeks/1.json
|
||||||
|
def update
|
||||||
|
respond_to do |format|
|
||||||
|
if @week.update(admin_week_params)
|
||||||
|
format.js { collection }
|
||||||
|
format.html { redirect_to [:admin, @week], notice: 'Week was successfully updated.' }
|
||||||
|
format.json { render :show, status: :ok, location: @week }
|
||||||
|
else
|
||||||
|
format.js { render :edit }
|
||||||
|
format.html { render :edit }
|
||||||
|
format.json { render json: @week.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /admin/weeks/1
|
||||||
|
# DELETE /admin/weeks/1.json
|
||||||
|
def destroy
|
||||||
|
@week.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.js { collection }
|
||||||
|
format.html { redirect_to admin_weeks_url, notice: 'Week was successfully destroyed.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
def set_object
|
||||||
|
@week = Week.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def collection
|
||||||
|
@weeks = Week.by_course(params[:course_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
def admin_week_params
|
||||||
|
params.require(:week).permit(:name, :description)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -3,4 +3,6 @@
|
||||||
class Course < ApplicationRecord
|
class Course < ApplicationRecord
|
||||||
has_many :weeks, dependent: :destroy
|
has_many :weeks, dependent: :destroy
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
|
scope :name_asc, -> { order('name ASC') }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Week < ApplicationRecord
|
class Week < ApplicationRecord
|
||||||
belongs_to :course
|
belongs_to :course
|
||||||
|
|
||||||
|
scope :by_course, ->(c_id) { where(course_id: c_id) }
|
||||||
|
scope :name_asc, -> { order('name ASC') }
|
||||||
|
scope :name_desc, -> { order('name DESC') }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,37 @@
|
||||||
require "rails_helper"
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::CoursesController, type: :routing do
|
RSpec.describe Admin::CoursesController, type: :routing do
|
||||||
describe "routing" do
|
describe 'routing' do
|
||||||
it "routes to #index" do
|
it 'routes to #index' do
|
||||||
expect(:get => "/admin/courses").to route_to("admin/courses#index")
|
expect(get: '/admin/courses').to route_to('admin/courses#index')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #new" do
|
it 'routes to #new' do
|
||||||
expect(:get => "/admin/courses/new").to route_to("admin/courses#new")
|
expect(get: '/admin/courses/new').to route_to('admin/courses#new')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #show" do
|
it 'routes to #show' do
|
||||||
expect(:get => "/admin/courses/1").to route_to("admin/courses#show", :id => "1")
|
expect(get: '/admin/courses/1').to route_to('admin/courses#show', id: '1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #edit" do
|
it 'routes to #edit' do
|
||||||
expect(:get => "/admin/courses/1/edit").to route_to("admin/courses#edit", :id => "1")
|
expect(get: '/admin/courses/1/edit').to route_to('admin/courses#edit', id: '1')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'routes to #create' do
|
||||||
it "routes to #create" do
|
expect(post: '/admin/courses').to route_to('admin/courses#create')
|
||||||
expect(:post => "/admin/courses").to route_to("admin/courses#create")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #update via PUT" do
|
it 'routes to #update via PUT' do
|
||||||
expect(:put => "/admin/courses/1").to route_to("admin/courses#update", :id => "1")
|
expect(put: '/admin/courses/1').to route_to('admin/courses#update', id: '1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #update via PATCH" do
|
it 'routes to #update via PATCH' do
|
||||||
expect(:patch => "/admin/courses/1").to route_to("admin/courses#update", :id => "1")
|
expect(patch: '/admin/courses/1').to route_to('admin/courses#update', id: '1')
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes to #destroy" do
|
it 'routes to #destroy' do
|
||||||
expect(:delete => "/admin/courses/1").to route_to("admin/courses#destroy", :id => "1")
|
expect(delete: '/admin/courses/1').to route_to('admin/courses#destroy', id: '1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "admin/courses/edit", type: :view do
|
RSpec.describe 'admin/courses/edit', type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@admin_course = assign(:admin_course, Admin::Course.create!(
|
@admin_course = assign(:admin_course, Admin::Course.create!(
|
||||||
:name => "MyString",
|
name: 'MyString',
|
||||||
:description => "MyText"
|
description: 'MyText'
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders the edit admin_course form" do
|
it 'renders the edit admin_course form' do
|
||||||
render
|
render
|
||||||
|
|
||||||
assert_select "form[action=?][method=?]", admin_course_path(@admin_course), "post" do
|
assert_select 'form[action=?][method=?]', admin_course_path(@admin_course), 'post' do
|
||||||
|
assert_select 'input[name=?]', 'admin_course[name]'
|
||||||
|
|
||||||
assert_select "input[name=?]", "admin_course[name]"
|
assert_select 'textarea[name=?]', 'admin_course[description]'
|
||||||
|
|
||||||
assert_select "textarea[name=?]", "admin_course[description]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "admin/courses/index", type: :view do
|
RSpec.describe 'admin/courses/index', type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
assign(:admin_courses, [
|
assign(:admin_courses, [
|
||||||
Admin::Course.create!(
|
Admin::Course.create!(
|
||||||
:name => "Name",
|
name: 'Name',
|
||||||
:description => "MyText"
|
description: 'MyText'
|
||||||
),
|
),
|
||||||
Admin::Course.create!(
|
Admin::Course.create!(
|
||||||
:name => "Name",
|
name: 'Name',
|
||||||
:description => "MyText"
|
description: 'MyText'
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders a list of admin/courses" do
|
it 'renders a list of admin/courses' do
|
||||||
render
|
render
|
||||||
assert_select "tr>td", :text => "Name".to_s, :count => 2
|
assert_select 'tr>td', text: 'Name'.to_s, count: 2
|
||||||
assert_select "tr>td", :text => "MyText".to_s, :count => 2
|
assert_select 'tr>td', text: 'MyText'.to_s, count: 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,20 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "admin/courses/new", type: :view do
|
RSpec.describe 'admin/courses/new', type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
assign(:admin_course, Admin::Course.new(
|
assign(:admin_course, Admin::Course.new(
|
||||||
:name => "MyString",
|
name: 'MyString',
|
||||||
:description => "MyText"
|
description: 'MyText'
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders new admin_course form" do
|
it 'renders new admin_course form' do
|
||||||
render
|
render
|
||||||
|
|
||||||
assert_select "form[action=?][method=?]", admin_courses_path, "post" do
|
assert_select 'form[action=?][method=?]', admin_courses_path, 'post' do
|
||||||
|
assert_select 'input[name=?]', 'admin_course[name]'
|
||||||
|
|
||||||
assert_select "input[name=?]", "admin_course[name]"
|
assert_select 'textarea[name=?]', 'admin_course[description]'
|
||||||
|
|
||||||
assert_select "textarea[name=?]", "admin_course[description]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe "admin/courses/show", type: :view do
|
RSpec.describe 'admin/courses/show', type: :view do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@admin_course = assign(:admin_course, Admin::Course.create!(
|
@admin_course = assign(:admin_course, Admin::Course.create!(
|
||||||
:name => "Name",
|
name: 'Name',
|
||||||
:description => "MyText"
|
description: 'MyText'
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders attributes in <p>" do
|
it 'renders attributes in <p>' do
|
||||||
render
|
render
|
||||||
expect(rendered).to match(/Name/)
|
expect(rendered).to match(/Name/)
|
||||||
expect(rendered).to match(/MyText/)
|
expect(rendered).to match(/MyText/)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue