create sponsor_tier
This commit is contained in:
parent
cb089b1bb8
commit
0a460d1d37
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the SponsorTiers controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,74 @@
|
|||
class SponsorTiersController < ApplicationController
|
||||
before_action :set_sponsor_tier, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /sponsor_tiers
|
||||
# GET /sponsor_tiers.json
|
||||
def index
|
||||
@sponsor_tiers = SponsorTier.all
|
||||
end
|
||||
|
||||
# GET /sponsor_tiers/1
|
||||
# GET /sponsor_tiers/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /sponsor_tiers/new
|
||||
def new
|
||||
@sponsor_tier = SponsorTier.new
|
||||
end
|
||||
|
||||
# GET /sponsor_tiers/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /sponsor_tiers
|
||||
# POST /sponsor_tiers.json
|
||||
def create
|
||||
@sponsor_tier = SponsorTier.new(sponsor_tier_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @sponsor_tier.save
|
||||
format.html { redirect_to @sponsor_tier, notice: 'Sponsor tier was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @sponsor_tier }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /sponsor_tiers/1
|
||||
# PATCH/PUT /sponsor_tiers/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @sponsor_tier.update(sponsor_tier_params)
|
||||
format.html { redirect_to @sponsor_tier, notice: 'Sponsor tier was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @sponsor_tier }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @sponsor_tier.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /sponsor_tiers/1
|
||||
# DELETE /sponsor_tiers/1.json
|
||||
def destroy
|
||||
@sponsor_tier.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to sponsor_tiers_url, notice: 'Sponsor tier was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_sponsor_tier
|
||||
@sponsor_tier = SponsorTier.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def sponsor_tier_params
|
||||
params.require(:sponsor_tier).permit(:tier)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module SponsorTiersHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
class SponsorTier < ApplicationRecord
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
<%= simple_form_for(@sponsor_tier) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :tier %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<%= f.button :submit %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -0,0 +1,2 @@
|
|||
json.extract! sponsor_tier, :id, :tier, :created_at, :updated_at
|
||||
json.url sponsor_tier_url(sponsor_tier, format: :json)
|
|
@ -0,0 +1,6 @@
|
|||
<h1>Editing Sponsor Tier</h1>
|
||||
|
||||
<%= render 'form', sponsor_tier: @sponsor_tier %>
|
||||
|
||||
<%= link_to 'Show', @sponsor_tier %> |
|
||||
<%= link_to 'Back', sponsor_tiers_path %>
|
|
@ -0,0 +1,27 @@
|
|||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<h1>Sponsor Tiers</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tier</th>
|
||||
<th colspan="3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @sponsor_tiers.each do |sponsor_tier| %>
|
||||
<tr>
|
||||
<td><%= sponsor_tier.tier %></td>
|
||||
<td><%= link_to 'Show', sponsor_tier %></td>
|
||||
<td><%= link_to 'Edit', edit_sponsor_tier_path(sponsor_tier) %></td>
|
||||
<td><%= link_to 'Destroy', sponsor_tier, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<%= link_to 'New Sponsor Tier', new_sponsor_tier_path %>
|
|
@ -0,0 +1 @@
|
|||
json.array! @sponsor_tiers, partial: "sponsor_tiers/sponsor_tier", as: :sponsor_tier
|
|
@ -0,0 +1,5 @@
|
|||
<h1>New Sponsor Tier</h1>
|
||||
|
||||
<%= render 'form', sponsor_tier: @sponsor_tier %>
|
||||
|
||||
<%= link_to 'Back', sponsor_tiers_path %>
|
|
@ -0,0 +1,9 @@
|
|||
<p id="notice"><%= notice %></p>
|
||||
|
||||
<p>
|
||||
<strong>Tier:</strong>
|
||||
<%= @sponsor_tier.tier %>
|
||||
</p>
|
||||
|
||||
<%= link_to 'Edit', edit_sponsor_tier_path(@sponsor_tier) %> |
|
||||
<%= link_to 'Back', sponsor_tiers_path %>
|
|
@ -0,0 +1 @@
|
|||
json.partial! "sponsor_tiers/sponsor_tier", sponsor_tier: @sponsor_tier
|
|
@ -1,5 +1,6 @@
|
|||
Rails.application.routes.draw do
|
||||
|
||||
resources :sponsor_tiers
|
||||
resources :sponsorships
|
||||
require 'sidekiq/web'
|
||||
require 'admin_constraint'
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class CreateSponsorTiers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :sponsor_tiers do |t|
|
||||
t.integer :tier
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class AddColumnToSponsorTiers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :sponsor_tiers, :description, :string, default: ""
|
||||
add_column :sponsor_tiers, :user_id, :integer
|
||||
end
|
||||
end
|
|
@ -0,0 +1,141 @@
|
|||
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.
|
||||
#
|
||||
# Also compared to earlier versions of this generator, there are no longer any
|
||||
# expectations of assigns and templates rendered. These features have been
|
||||
# removed from Rails core in Rails 5, but can be added back in via the
|
||||
# `rails-controller-testing` gem.
|
||||
|
||||
RSpec.describe SponsorTiersController, type: :controller do
|
||||
|
||||
# This should return the minimal set of attributes required to create a valid
|
||||
# SponsorTier. As you add validations to SponsorTier, 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
|
||||
# SponsorTiersController. Be sure to keep this updated too.
|
||||
let(:valid_session) { {} }
|
||||
|
||||
describe "GET #index" do
|
||||
it "returns a success response" do
|
||||
SponsorTier.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
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
get :show, params: {id: sponsor_tier.to_param}, session: valid_session
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #new" do
|
||||
it "returns a success response" do
|
||||
get :new, params: {}, session: valid_session
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "returns a success response" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
get :edit, params: {id: sponsor_tier.to_param}, session: valid_session
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
it "creates a new SponsorTier" do
|
||||
expect {
|
||||
post :create, params: {sponsor_tier: valid_attributes}, session: valid_session
|
||||
}.to change(SponsorTier, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the created sponsor_tier" do
|
||||
post :create, params: {sponsor_tier: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(SponsorTier.last)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "returns a success response (i.e. to display the 'new' template)" do
|
||||
post :create, params: {sponsor_tier: invalid_attributes}, session: valid_session
|
||||
expect(response).to be_successful
|
||||
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 sponsor_tier" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
put :update, params: {id: sponsor_tier.to_param, sponsor_tier: new_attributes}, session: valid_session
|
||||
sponsor_tier.reload
|
||||
skip("Add assertions for updated state")
|
||||
end
|
||||
|
||||
it "redirects to the sponsor_tier" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
put :update, params: {id: sponsor_tier.to_param, sponsor_tier: valid_attributes}, session: valid_session
|
||||
expect(response).to redirect_to(sponsor_tier)
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid params" do
|
||||
it "returns a success response (i.e. to display the 'edit' template)" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
put :update, params: {id: sponsor_tier.to_param, sponsor_tier: invalid_attributes}, session: valid_session
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested sponsor_tier" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
expect {
|
||||
delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session
|
||||
}.to change(SponsorTier, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the sponsor_tiers list" do
|
||||
sponsor_tier = SponsorTier.create! valid_attributes
|
||||
delete :destroy, params: {id: sponsor_tier.to_param}, session: valid_session
|
||||
expect(response).to redirect_to(sponsor_tiers_url)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the SponsorTiersHelper. For example:
|
||||
#
|
||||
# describe SponsorTiersHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe SponsorTiersHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SponsorTier, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "SponsorTiers", type: :request do
|
||||
describe "GET /sponsor_tiers" do
|
||||
it "works! (now write some real specs)" do
|
||||
get sponsor_tiers_path
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,38 @@
|
|||
require "rails_helper"
|
||||
|
||||
RSpec.describe SponsorTiersController, type: :routing do
|
||||
describe "routing" do
|
||||
it "routes to #index" do
|
||||
expect(:get => "/sponsor_tiers").to route_to("sponsor_tiers#index")
|
||||
end
|
||||
|
||||
it "routes to #new" do
|
||||
expect(:get => "/sponsor_tiers/new").to route_to("sponsor_tiers#new")
|
||||
end
|
||||
|
||||
it "routes to #show" do
|
||||
expect(:get => "/sponsor_tiers/1").to route_to("sponsor_tiers#show", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #edit" do
|
||||
expect(:get => "/sponsor_tiers/1/edit").to route_to("sponsor_tiers#edit", :id => "1")
|
||||
end
|
||||
|
||||
|
||||
it "routes to #create" do
|
||||
expect(:post => "/sponsor_tiers").to route_to("sponsor_tiers#create")
|
||||
end
|
||||
|
||||
it "routes to #update via PUT" do
|
||||
expect(:put => "/sponsor_tiers/1").to route_to("sponsor_tiers#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #update via PATCH" do
|
||||
expect(:patch => "/sponsor_tiers/1").to route_to("sponsor_tiers#update", :id => "1")
|
||||
end
|
||||
|
||||
it "routes to #destroy" do
|
||||
expect(:delete => "/sponsor_tiers/1").to route_to("sponsor_tiers#destroy", :id => "1")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "sponsor_tiers/edit", type: :view do
|
||||
before(:each) do
|
||||
@sponsor_tier = assign(:sponsor_tier, SponsorTier.create!(
|
||||
:tier => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders the edit sponsor_tier form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", sponsor_tier_path(@sponsor_tier), "post" do
|
||||
|
||||
assert_select "input[name=?]", "sponsor_tier[tier]"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "sponsor_tiers/index", type: :view do
|
||||
before(:each) do
|
||||
assign(:sponsor_tiers, [
|
||||
SponsorTier.create!(
|
||||
:tier => 2
|
||||
),
|
||||
SponsorTier.create!(
|
||||
:tier => 2
|
||||
)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of sponsor_tiers" do
|
||||
render
|
||||
assert_select "tr>td", :text => 2.to_s, :count => 2
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "sponsor_tiers/new", type: :view do
|
||||
before(:each) do
|
||||
assign(:sponsor_tier, SponsorTier.new(
|
||||
:tier => 1
|
||||
))
|
||||
end
|
||||
|
||||
it "renders new sponsor_tier form" do
|
||||
render
|
||||
|
||||
assert_select "form[action=?][method=?]", sponsor_tiers_path, "post" do
|
||||
|
||||
assert_select "input[name=?]", "sponsor_tier[tier]"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "sponsor_tiers/show", type: :view do
|
||||
before(:each) do
|
||||
@sponsor_tier = assign(:sponsor_tier, SponsorTier.create!(
|
||||
:tier => 2
|
||||
))
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
expect(rendered).to match(/2/)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue