diff --git a/app/assets/javascripts/commissions.coffee b/app/assets/javascripts/commissions.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/commissions.coffee @@ -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://coffeescript.org/ diff --git a/app/assets/stylesheets/commissions.scss b/app/assets/stylesheets/commissions.scss new file mode 100644 index 00000000..96690bb7 --- /dev/null +++ b/app/assets/stylesheets/commissions.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Commissions controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/commissions_controller.rb b/app/controllers/commissions_controller.rb new file mode 100644 index 00000000..706e3459 --- /dev/null +++ b/app/controllers/commissions_controller.rb @@ -0,0 +1,74 @@ +class CommissionsController < ApplicationController + before_action :set_commission, only: [:show, :edit, :update, :destroy] + + # GET /commissions + # GET /commissions.json + def index + @commissions = Commission.all + end + + # GET /commissions/1 + # GET /commissions/1.json + def show + end + + # GET /commissions/new + def new + @commission = Commission.new + end + + # GET /commissions/1/edit + def edit + end + + # POST /commissions + # POST /commissions.json + def create + @commission = Commission.new(commission_params) + + respond_to do |format| + if @commission.save + format.html { redirect_to @commission, notice: 'Commission was successfully created.' } + format.json { render :show, status: :created, location: @commission } + else + format.html { render :new } + format.json { render json: @commission.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /commissions/1 + # PATCH/PUT /commissions/1.json + def update + respond_to do |format| + if @commission.update(commission_params) + format.html { redirect_to @commission, notice: 'Commission was successfully updated.' } + format.json { render :show, status: :ok, location: @commission } + else + format.html { render :edit } + format.json { render json: @commission.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /commissions/1 + # DELETE /commissions/1.json + def destroy + @commission.destroy + respond_to do |format| + format.html { redirect_to commissions_url, notice: 'Commission was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_commission + @commission = Commission.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def commission_params + params.fetch(:commission, {}) + end +end diff --git a/app/helpers/commissions_helper.rb b/app/helpers/commissions_helper.rb new file mode 100644 index 00000000..02f2dddf --- /dev/null +++ b/app/helpers/commissions_helper.rb @@ -0,0 +1,2 @@ +module CommissionsHelper +end diff --git a/app/models/commission.rb b/app/models/commission.rb new file mode 100644 index 00000000..8d14db70 --- /dev/null +++ b/app/models/commission.rb @@ -0,0 +1,2 @@ +class Commission < ApplicationRecord +end diff --git a/app/views/commissions/_commission.json.jbuilder b/app/views/commissions/_commission.json.jbuilder new file mode 100644 index 00000000..3e096d8b --- /dev/null +++ b/app/views/commissions/_commission.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! commission, :id, :created_at, :updated_at +json.url commission_url(commission, format: :json) diff --git a/app/views/commissions/_form.html.erb b/app/views/commissions/_form.html.erb new file mode 100644 index 00000000..40c96de7 --- /dev/null +++ b/app/views/commissions/_form.html.erb @@ -0,0 +1,10 @@ +<%= simple_form_for(@commission) do |f| %> + <%= f.error_notification %> + +
<%= notice %>
+ +| + | ||
|---|---|---|
| <%= link_to 'Show', commission %> | +<%= link_to 'Edit', edit_commission_path(commission) %> | +<%= link_to 'Destroy', commission, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ +<%= link_to 'Edit', edit_commission_path(@commission) %> | +<%= link_to 'Back', commissions_path %> diff --git a/app/views/commissions/show.json.jbuilder b/app/views/commissions/show.json.jbuilder new file mode 100644 index 00000000..c51e1254 --- /dev/null +++ b/app/views/commissions/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "commissions/commission", commission: @commission diff --git a/db/migrate/20170821093252_create_commissions.rb b/db/migrate/20170821093252_create_commissions.rb new file mode 100644 index 00000000..ebd7d8dd --- /dev/null +++ b/db/migrate/20170821093252_create_commissions.rb @@ -0,0 +1,11 @@ +class CreateCommissions < ActiveRecord::Migration[5.1] + def change + create_table :commissions do |t| + t.integer :product_id, null: false + t.integer :amount + t.string :commission_type + t.boolean :is_active + t.timestamps + end + end +end diff --git a/spec/controllers/commissions_controller_spec.rb b/spec/controllers/commissions_controller_spec.rb new file mode 100644 index 00000000..28925593 --- /dev/null +++ b/spec/controllers/commissions_controller_spec.rb @@ -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 CommissionsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Commission. As you add validations to Commission, 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 + # CommissionsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + commission = Commission.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #show" do + it "returns a success response" do + commission = Commission.create! valid_attributes + get :show, params: {id: commission.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #edit" do + it "returns a success response" do + commission = Commission.create! valid_attributes + get :edit, params: {id: commission.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Commission" do + expect { + post :create, params: {commission: valid_attributes}, session: valid_session + }.to change(Commission, :count).by(1) + end + + it "redirects to the created commission" do + post :create, params: {commission: valid_attributes}, session: valid_session + expect(response).to redirect_to(Commission.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {commission: invalid_attributes}, session: valid_session + expect(response).to be_success + 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 commission" do + commission = Commission.create! valid_attributes + put :update, params: {id: commission.to_param, commission: new_attributes}, session: valid_session + commission.reload + skip("Add assertions for updated state") + end + + it "redirects to the commission" do + commission = Commission.create! valid_attributes + put :update, params: {id: commission.to_param, commission: valid_attributes}, session: valid_session + expect(response).to redirect_to(commission) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + commission = Commission.create! valid_attributes + put :update, params: {id: commission.to_param, commission: invalid_attributes}, session: valid_session + expect(response).to be_success + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested commission" do + commission = Commission.create! valid_attributes + expect { + delete :destroy, params: {id: commission.to_param}, session: valid_session + }.to change(Commission, :count).by(-1) + end + + it "redirects to the commissions list" do + commission = Commission.create! valid_attributes + delete :destroy, params: {id: commission.to_param}, session: valid_session + expect(response).to redirect_to(commissions_url) + end + end + +end diff --git a/spec/helpers/commissions_helper_spec.rb b/spec/helpers/commissions_helper_spec.rb new file mode 100644 index 00000000..d939a734 --- /dev/null +++ b/spec/helpers/commissions_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CommissionsHelper. For example: +# +# describe CommissionsHelper 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 CommissionsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/commission_spec.rb b/spec/models/commission_spec.rb new file mode 100644 index 00000000..86010523 --- /dev/null +++ b/spec/models/commission_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Commission, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/commissions_spec.rb b/spec/requests/commissions_spec.rb new file mode 100644 index 00000000..bddd5e13 --- /dev/null +++ b/spec/requests/commissions_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Commissions", type: :request do + describe "GET /commissions" do + it "works! (now write some real specs)" do + get commissions_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/commissions_routing_spec.rb b/spec/routing/commissions_routing_spec.rb new file mode 100644 index 00000000..5d5fcafb --- /dev/null +++ b/spec/routing/commissions_routing_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe CommissionsController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/commissions").to route_to("commissions#index") + end + + it "routes to #new" do + expect(:get => "/commissions/new").to route_to("commissions#new") + end + + it "routes to #show" do + expect(:get => "/commissions/1").to route_to("commissions#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/commissions/1/edit").to route_to("commissions#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/commissions").to route_to("commissions#create") + end + + it "routes to #update via PUT" do + expect(:put => "/commissions/1").to route_to("commissions#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/commissions/1").to route_to("commissions#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/commissions/1").to route_to("commissions#destroy", :id => "1") + end + + end +end diff --git a/spec/views/commissions/edit.html.erb_spec.rb b/spec/views/commissions/edit.html.erb_spec.rb new file mode 100644 index 00000000..dd8529f9 --- /dev/null +++ b/spec/views/commissions/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "commissions/edit", type: :view do + before(:each) do + @commission = assign(:commission, Commission.create!()) + end + + it "renders the edit commission form" do + render + + assert_select "form[action=?][method=?]", commission_path(@commission), "post" do + end + end +end diff --git a/spec/views/commissions/index.html.erb_spec.rb b/spec/views/commissions/index.html.erb_spec.rb new file mode 100644 index 00000000..3ed203c9 --- /dev/null +++ b/spec/views/commissions/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "commissions/index", type: :view do + before(:each) do + assign(:commissions, [ + Commission.create!(), + Commission.create!() + ]) + end + + it "renders a list of commissions" do + render + end +end diff --git a/spec/views/commissions/new.html.erb_spec.rb b/spec/views/commissions/new.html.erb_spec.rb new file mode 100644 index 00000000..59fc2c9e --- /dev/null +++ b/spec/views/commissions/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "commissions/new", type: :view do + before(:each) do + assign(:commission, Commission.new()) + end + + it "renders new commission form" do + render + + assert_select "form[action=?][method=?]", commissions_path, "post" do + end + end +end diff --git a/spec/views/commissions/show.html.erb_spec.rb b/spec/views/commissions/show.html.erb_spec.rb new file mode 100644 index 00000000..71d889b5 --- /dev/null +++ b/spec/views/commissions/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "commissions/show", type: :view do + before(:each) do + @commission = assign(:commission, Commission.create!()) + end + + it "renders attributes in" do + render + end +end diff --git a/test/system/commissions_test.rb b/test/system/commissions_test.rb new file mode 100644 index 00000000..97506d42 --- /dev/null +++ b/test/system/commissions_test.rb @@ -0,0 +1,9 @@ +require "application_system_test_case" + +class CommissionsTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit commissions_url + # + # assert_selector "h1", text: "Commission" + # end +end