commit
ca581d0a8e
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the local_settings controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,84 @@
|
|||||||
|
class LocalSettingsController < ApplicationController
|
||||||
|
layout 'educoder'
|
||||||
|
# GET /local_settings
|
||||||
|
# GET /local_settings.json
|
||||||
|
def index
|
||||||
|
@local_settings = LocalSetting.all
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # index.html.erb
|
||||||
|
format.json { render json: @local_settings }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /local_settings/1
|
||||||
|
# GET /local_settings/1.json
|
||||||
|
def show
|
||||||
|
@local_setting = LocalSetting.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # show.html.erb
|
||||||
|
format.json { render json: @local_setting }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /local_settings/new
|
||||||
|
# GET /local_settings/new.json
|
||||||
|
def new
|
||||||
|
@local_setting = LocalSetting.new
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html # new.html.erb
|
||||||
|
format.json { render json: @local_setting }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /local_settings/1/edit
|
||||||
|
def edit
|
||||||
|
@local_setting = LocalSetting.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /local_settings
|
||||||
|
# POST /local_settings.json
|
||||||
|
def create
|
||||||
|
@local_setting = LocalSetting.new(params[:local_setting])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @local_setting.save
|
||||||
|
format.html { redirect_to @local_setting, notice: 'Local setting was successfully created.' }
|
||||||
|
format.json { render json: @local_setting, status: :created, location: @local_setting }
|
||||||
|
else
|
||||||
|
format.html { render action: "new" }
|
||||||
|
format.json { render json: @local_setting.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PUT /local_settings/1
|
||||||
|
# PUT /local_settings/1.json
|
||||||
|
def update
|
||||||
|
@local_setting = LocalSetting.find(params[:id])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @local_setting.update_attributes(params[:local_setting])
|
||||||
|
format.html { redirect_to @local_setting, notice: 'Local setting was successfully updated.' }
|
||||||
|
format.json { head :no_content }
|
||||||
|
else
|
||||||
|
format.html { render action: "edit" }
|
||||||
|
format.json { render json: @local_setting.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /local_settings/1
|
||||||
|
# DELETE /local_settings/1.json
|
||||||
|
def destroy
|
||||||
|
@local_setting = LocalSetting.find(params[:id])
|
||||||
|
@local_setting.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to local_settings_url }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,2 @@
|
|||||||
|
module LocalSettingsHelper
|
||||||
|
end
|
@ -0,0 +1,3 @@
|
|||||||
|
class LocalSetting < ActiveRecord::Base
|
||||||
|
attr_accessible :exam
|
||||||
|
end
|
@ -0,0 +1,21 @@
|
|||||||
|
<%= form_for(@local_setting) do |f| %>
|
||||||
|
<% if @local_setting.errors.any? %>
|
||||||
|
<div id="error_explanation">
|
||||||
|
<h2><%= pluralize(@local_setting.errors.count, "error") %> prohibited this local_setting from being saved:</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% @local_setting.errors.full_messages.each do |msg| %>
|
||||||
|
<li><%= msg %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="field">
|
||||||
|
<%= f.label :考试模式 %><br />
|
||||||
|
<%= f.check_box :exam %>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<%= f.submit %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
@ -0,0 +1,9 @@
|
|||||||
|
<div class="ml10">
|
||||||
|
<h1>编辑配置参数</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to '详情', @local_setting %> |
|
||||||
|
<%= link_to 'Back', local_settings_path %>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
<div class="ml10">
|
||||||
|
<h1>本地配置</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>考试模式</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% @local_settings.each do |local_setting| %>
|
||||||
|
<tr>
|
||||||
|
<td><%= local_setting.exam %></td>
|
||||||
|
<td><%= link_to '显示', local_setting %></td>
|
||||||
|
<td><%= link_to '编辑', edit_local_setting_path(local_setting) %></td>
|
||||||
|
<td><%= link_to '删除', local_setting, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<%= link_to '新增配置', new_local_setting_path %>
|
||||||
|
</div>
|
||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
<div class="ml10">
|
||||||
|
<h1>新建配置参数</h1>
|
||||||
|
|
||||||
|
<%= render 'form' %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', local_settings_path %>
|
||||||
|
|
||||||
|
</div>
|
@ -0,0 +1,12 @@
|
|||||||
|
<div class="ml10">
|
||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<b>考试模式:</b>
|
||||||
|
<%= @local_setting.exam %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<%= link_to '编辑', edit_local_setting_path(@local_setting) %> |
|
||||||
|
<%= link_to 'Back', local_settings_path %>
|
||||||
|
</div>
|
@ -0,0 +1,9 @@
|
|||||||
|
class CreateLocalSettings < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :local_settings do |t|
|
||||||
|
t.boolean :exam
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,159 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# This spec was generated by rspec-rails when you ran the scaffold generator.
|
||||||
|
# It demonstrates how one might use RSpec to specify the controller code that
|
||||||
|
# was generated by Rails when you ran the scaffold generator.
|
||||||
|
#
|
||||||
|
# It assumes that the implementation code is generated by the rails scaffold
|
||||||
|
# generator. If you are using any extension libraries to generate different
|
||||||
|
# controller code, this generated spec may or may not pass.
|
||||||
|
#
|
||||||
|
# It only uses APIs available in rails and/or rspec-rails. There are a number
|
||||||
|
# of tools you can use to make these specs even more expressive, but we're
|
||||||
|
# sticking to rails and rspec-rails APIs to keep things simple and stable.
|
||||||
|
#
|
||||||
|
# Compared to earlier versions of this generator, there is very limited use of
|
||||||
|
# stubs and message expectations in this spec. Stubs are only used when there
|
||||||
|
# is no simpler way to get a handle on the object needed for the example.
|
||||||
|
# Message expectations are only used when there is no simpler way to specify
|
||||||
|
# that an instance is receiving a specific message.
|
||||||
|
|
||||||
|
RSpec.describe LocalSettingsController, :type => :controller do
|
||||||
|
|
||||||
|
# This should return the minimal set of attributes required to create a valid
|
||||||
|
# LocalSetting. As you add validations to LocalSetting, be sure to
|
||||||
|
# adjust the attributes here as well.
|
||||||
|
let(:valid_attributes) {
|
||||||
|
skip("Add a hash of attributes valid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:invalid_attributes) {
|
||||||
|
skip("Add a hash of attributes invalid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
# This should return the minimal set of values that should be in the session
|
||||||
|
# in order to pass any filters (e.g. authentication) defined in
|
||||||
|
# LocalSettingsController. Be sure to keep this updated too.
|
||||||
|
let(:valid_session) { {} }
|
||||||
|
|
||||||
|
describe "GET #index" do
|
||||||
|
it "assigns all local_settings as @local_settings" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
get :index, {}, valid_session
|
||||||
|
expect(assigns(:local_settings)).to eq([local_setting])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #show" do
|
||||||
|
it "assigns the requested local_setting as @local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
get :show, {:id => local_setting.to_param}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to eq(local_setting)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #new" do
|
||||||
|
it "assigns a new local_setting as @local_setting" do
|
||||||
|
get :new, {}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to be_a_new(LocalSetting)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET #edit" do
|
||||||
|
it "assigns the requested local_setting as @local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
get :edit, {:id => local_setting.to_param}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to eq(local_setting)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "POST #create" do
|
||||||
|
context "with valid params" do
|
||||||
|
it "creates a new LocalSetting" do
|
||||||
|
expect {
|
||||||
|
post :create, {:local_setting => valid_attributes}, valid_session
|
||||||
|
}.to change(LocalSetting, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns a newly created local_setting as @local_setting" do
|
||||||
|
post :create, {:local_setting => valid_attributes}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to be_a(LocalSetting)
|
||||||
|
expect(assigns(:local_setting)).to be_persisted
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the created local_setting" do
|
||||||
|
post :create, {:local_setting => valid_attributes}, valid_session
|
||||||
|
expect(response).to redirect_to(LocalSetting.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with invalid params" do
|
||||||
|
it "assigns a newly created but unsaved local_setting as @local_setting" do
|
||||||
|
post :create, {:local_setting => invalid_attributes}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to be_a_new(LocalSetting)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'new' template" do
|
||||||
|
post :create, {:local_setting => invalid_attributes}, valid_session
|
||||||
|
expect(response).to render_template("new")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "PUT #update" do
|
||||||
|
context "with valid params" do
|
||||||
|
let(:new_attributes) {
|
||||||
|
skip("Add a hash of attributes valid for your model")
|
||||||
|
}
|
||||||
|
|
||||||
|
it "updates the requested local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
put :update, {:id => local_setting.to_param, :local_setting => new_attributes}, valid_session
|
||||||
|
local_setting.reload
|
||||||
|
skip("Add assertions for updated state")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assigns the requested local_setting as @local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
put :update, {:id => local_setting.to_param, :local_setting => valid_attributes}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to eq(local_setting)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
put :update, {:id => local_setting.to_param, :local_setting => valid_attributes}, valid_session
|
||||||
|
expect(response).to redirect_to(local_setting)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with invalid params" do
|
||||||
|
it "assigns the local_setting as @local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
put :update, {:id => local_setting.to_param, :local_setting => invalid_attributes}, valid_session
|
||||||
|
expect(assigns(:local_setting)).to eq(local_setting)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "re-renders the 'edit' template" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
put :update, {:id => local_setting.to_param, :local_setting => invalid_attributes}, valid_session
|
||||||
|
expect(response).to render_template("edit")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "DELETE #destroy" do
|
||||||
|
it "destroys the requested local_setting" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
expect {
|
||||||
|
delete :destroy, {:id => local_setting.to_param}, valid_session
|
||||||
|
}.to change(LocalSetting, :count).by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects to the local_settings list" do
|
||||||
|
local_setting = LocalSetting.create! valid_attributes
|
||||||
|
delete :destroy, {:id => local_setting.to_param}, valid_session
|
||||||
|
expect(response).to redirect_to(local_settings_url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,6 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :local_setting do
|
||||||
|
exam false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe LocalSetting, :type => :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue