diff --git a/app/assets/javascripts/sponsor_tiers.js b/app/assets/javascripts/sponsor_tiers.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/sponsor_tiers.js @@ -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. diff --git a/app/assets/javascripts/sponsorships.js b/app/assets/javascripts/sponsorships.js new file mode 100644 index 00000000..dee720fa --- /dev/null +++ b/app/assets/javascripts/sponsorships.js @@ -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. diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 00000000..60451880 --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} diff --git a/app/assets/stylesheets/sponsor_tiers.scss b/app/assets/stylesheets/sponsor_tiers.scss new file mode 100644 index 00000000..0b4b39a0 --- /dev/null +++ b/app/assets/stylesheets/sponsor_tiers.scss @@ -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/ diff --git a/app/assets/stylesheets/sponsorships.scss b/app/assets/stylesheets/sponsorships.scss new file mode 100644 index 00000000..3d9a20ea --- /dev/null +++ b/app/assets/stylesheets/sponsorships.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Sponsorships 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/sponsor_tiers_controller.rb b/app/controllers/sponsor_tiers_controller.rb new file mode 100644 index 00000000..3f1273ab --- /dev/null +++ b/app/controllers/sponsor_tiers_controller.rb @@ -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 diff --git a/app/controllers/sponsorships_controller.rb b/app/controllers/sponsorships_controller.rb new file mode 100644 index 00000000..508350f2 --- /dev/null +++ b/app/controllers/sponsorships_controller.rb @@ -0,0 +1,74 @@ +class SponsorshipsController < ApplicationController + before_action :set_sponsorship, only: [:show, :edit, :update, :destroy] + + # GET /sponsorships + # GET /sponsorships.json + def index + @sponsorships = Sponsorship.all + end + + # GET /sponsorships/1 + # GET /sponsorships/1.json + def show + end + + # GET /sponsorships/new + def new + @sponsorship = Sponsorship.new + end + + # GET /sponsorships/1/edit + def edit + end + + # POST /sponsorships + # POST /sponsorships.json + def create + @sponsorship = Sponsorship.new(sponsorship_params) + + respond_to do |format| + if @sponsorship.save + format.html { redirect_to @sponsorship, notice: 'Sponsorship was successfully created.' } + format.json { render :show, status: :created, location: @sponsorship } + else + format.html { render :new } + format.json { render json: @sponsorship.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /sponsorships/1 + # PATCH/PUT /sponsorships/1.json + def update + respond_to do |format| + if @sponsorship.update(sponsorship_params) + format.html { redirect_to @sponsorship, notice: 'Sponsorship was successfully updated.' } + format.json { render :show, status: :ok, location: @sponsorship } + else + format.html { render :edit } + format.json { render json: @sponsorship.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /sponsorships/1 + # DELETE /sponsorships/1.json + def destroy + @sponsorship.destroy + respond_to do |format| + format.html { redirect_to sponsorships_url, notice: 'Sponsorship was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_sponsorship + @sponsorship = Sponsorship.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def sponsorship_params + params.require(:sponsorship).permit(:amount, :visible, :sponsor_id, :developer_id) + end +end diff --git a/app/helpers/sponsor_tiers_helper.rb b/app/helpers/sponsor_tiers_helper.rb new file mode 100644 index 00000000..02b198bd --- /dev/null +++ b/app/helpers/sponsor_tiers_helper.rb @@ -0,0 +1,2 @@ +module SponsorTiersHelper +end diff --git a/app/helpers/sponsorships_helper.rb b/app/helpers/sponsorships_helper.rb new file mode 100644 index 00000000..f6ea1f0d --- /dev/null +++ b/app/helpers/sponsorships_helper.rb @@ -0,0 +1,2 @@ +module SponsorshipsHelper +end diff --git a/app/models/coin_change.rb b/app/models/coin_change.rb new file mode 100644 index 00000000..f5e066fb --- /dev/null +++ b/app/models/coin_change.rb @@ -0,0 +1,5 @@ +class CoinChange < ApplicationRecord + belongs_to :to_wallet, class_name: 'Wallet' + belongs_to :from_wallet, class_name: 'Wallet' + validates :amount, presence: true +end diff --git a/app/models/passed_waitlist.rb b/app/models/passed_waitlist.rb new file mode 100644 index 00000000..a658cb7d --- /dev/null +++ b/app/models/passed_waitlist.rb @@ -0,0 +1,4 @@ +class PassedWaitlist < ApplicationRecord + belongs_to :applicant, class_name: 'User' + belongs_to :reviewer, class_name: 'User' +end diff --git a/app/models/sponsor_tier.rb b/app/models/sponsor_tier.rb new file mode 100644 index 00000000..20aed963 --- /dev/null +++ b/app/models/sponsor_tier.rb @@ -0,0 +1,3 @@ +class SponsorTier < ApplicationRecord + belongs_to :user +end diff --git a/app/models/sponsorship.rb b/app/models/sponsorship.rb new file mode 100644 index 00000000..e2d44801 --- /dev/null +++ b/app/models/sponsorship.rb @@ -0,0 +1,5 @@ +class Sponsorship < ApplicationRecord + belongs_to :sponsor, class_name: 'User' + belongs_to :developer, class_name: 'User' + validates :amount, presence: true +end diff --git a/app/models/stopped_sponsorship.rb b/app/models/stopped_sponsorship.rb new file mode 100644 index 00000000..b73ba273 --- /dev/null +++ b/app/models/stopped_sponsorship.rb @@ -0,0 +1,5 @@ +class StoppedSponsorship < ApplicationRecord + belongs_to :sponsor, class_name: 'User' + belongs_to :developer, class_name: 'User' + validates :amount, presence: true +end diff --git a/app/models/user.rb b/app/models/user.rb index f919ed1b..0ad5f541 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -92,6 +92,19 @@ class User < ApplicationRecord # has_many :libraries, dependent: :destroy has_many :project_trends, dependent: :destroy + # sponsor + has_many :as_sponsors, class_name: 'Sponsorship', foreign_key: 'sponsor_id', dependent: :destroy + has_many :as_sponsored, class_name: 'Sponsorship', foreign_key: 'developer_id', dependent: :destroy + has_many :stopped_sponsors, class_name: 'StoppedSponsorship', foreign_key: 'sponsor_id', dependent: :destroy + has_many :stopped_sponsored, class_name: 'StoppedSponsorship', foreign_key: 'developer_id', dependent: :destroy + has_many :sponsor_tier, dependent: :destroy + has_one :wallet, dependent: :destroy + has_many :waitlist, class_name: 'Waitlist', foreign_key: 'reviewer_id', optional: true + has_many :passed_waitlist, class_name: 'PassedWaitlist', foreign_key: 'reviewer_id', optional: true #as reviewer + has_one :application, class_name: 'Waitlist', foreign_key: 'applicant_id', optional: true + has_one :passed_application, class_name: 'PassedWaitlist', foreign_key: 'applicant_id', optional: true + + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| diff --git a/app/models/waitlist.rb b/app/models/waitlist.rb new file mode 100644 index 00000000..0c058eb7 --- /dev/null +++ b/app/models/waitlist.rb @@ -0,0 +1,4 @@ +class Waitlist < ApplicationRecord + belongs_to :applicant, class_name: 'User' + belongs_to :reviewer, class_name: 'User', optional: true +end diff --git a/app/models/wallet.rb b/app/models/wallet.rb new file mode 100644 index 00000000..e7e78671 --- /dev/null +++ b/app/models/wallet.rb @@ -0,0 +1,6 @@ +class Wallet < ApplicationRecord + belongs_to :user + has_many :outcome, class_name: 'CoinChange', foreign_key: 'from_wallet_id', dependent: :destroy + has_many :income, class_name: 'CoinChange', foreign_key: 'to_wallet_id', dependent: :destroy + validates :balance, presence: true +end diff --git a/app/views/sponsor_tiers/_form.html.erb b/app/views/sponsor_tiers/_form.html.erb new file mode 100644 index 00000000..1857620d --- /dev/null +++ b/app/views/sponsor_tiers/_form.html.erb @@ -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? %> + +
<%= notice %>
+ +Tier | ++ | ||
---|---|---|---|
<%= sponsor_tier.tier %> | +<%= link_to 'Show', sponsor_tier %> | +<%= link_to 'Edit', edit_sponsor_tier_path(sponsor_tier) %> | +<%= link_to 'Destroy', sponsor_tier, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Tier: + <%= @sponsor_tier.tier %> +
+ +<%= link_to 'Edit', edit_sponsor_tier_path(@sponsor_tier) %> | +<%= link_to 'Back', sponsor_tiers_path %> diff --git a/app/views/sponsor_tiers/show.json.jbuilder b/app/views/sponsor_tiers/show.json.jbuilder new file mode 100644 index 00000000..9244b22f --- /dev/null +++ b/app/views/sponsor_tiers/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "sponsor_tiers/sponsor_tier", sponsor_tier: @sponsor_tier diff --git a/app/views/sponsorships/_form.html.erb b/app/views/sponsorships/_form.html.erb new file mode 100644 index 00000000..aba15064 --- /dev/null +++ b/app/views/sponsorships/_form.html.erb @@ -0,0 +1,16 @@ + +<%= simple_form_for(@sponsorship) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + +<%= notice %>
+ +Amount | +Visible | +Sponsor | +Developer | ++ | ||
---|---|---|---|---|---|---|
<%= sponsorship.amount %> | +<%= sponsorship.visible %> | +<%= sponsorship.sponsor_id %> | +<%= sponsorship.developer_id %> | +<%= link_to 'Show', sponsorship %> | +<%= link_to 'Edit', edit_sponsorship_path(sponsorship) %> | +<%= link_to 'Destroy', sponsorship, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ ++ Amount: + <%= @sponsorship.amount %> +
+ ++ Visible: + <%= @sponsorship.visible %> +
+ ++ Sponsor: + <%= @sponsorship.sponsor_id %> +
+ ++ Developer: + <%= @sponsorship.developer_id %> +
+ +<%= link_to 'Edit', edit_sponsorship_path(@sponsorship) %> | +<%= link_to 'Back', sponsorships_path %> diff --git a/app/views/sponsorships/show.json.jbuilder b/app/views/sponsorships/show.json.jbuilder new file mode 100644 index 00000000..87ded287 --- /dev/null +++ b/app/views/sponsorships/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "sponsorships/sponsorship", sponsorship: @sponsorship diff --git a/config/routes.rb b/config/routes.rb index 45ba4855..939251c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Rails.application.routes.draw do + resources :sponsor_tiers + resources :sponsorships require 'sidekiq/web' require 'admin_constraint' diff --git a/db/migrate/20200724085032_add_column_to_table_users.rb b/db/migrate/20200724085032_add_column_to_table_users.rb new file mode 100644 index 00000000..3fa706ac --- /dev/null +++ b/db/migrate/20200724085032_add_column_to_table_users.rb @@ -0,0 +1,8 @@ +class AddColumnToTableUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :description, :string, default: "" + add_column :users, :sponsor_certification, :integer, default: 0 + add_column :users, :sponsor_num, :integer, default: 0 + add_column :users, :sponsored_num, :integer, default: 0 + end +end diff --git a/db/migrate/20200724090750_create_sponsorships.rb b/db/migrate/20200724090750_create_sponsorships.rb new file mode 100644 index 00000000..6feb9892 --- /dev/null +++ b/db/migrate/20200724090750_create_sponsorships.rb @@ -0,0 +1,12 @@ +class CreateSponsorships < ActiveRecord::Migration[5.2] + def change + create_table :sponsorships do |t| + t.integer :amount + t.integer :visible + t.integer :sponsor_id + t.integer :developer_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724093202_create_sponsor_tiers.rb b/db/migrate/20200724093202_create_sponsor_tiers.rb new file mode 100644 index 00000000..14317f9a --- /dev/null +++ b/db/migrate/20200724093202_create_sponsor_tiers.rb @@ -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 diff --git a/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb b/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb new file mode 100644 index 00000000..8210315d --- /dev/null +++ b/db/migrate/20200724093530_add_column_to_sponsor_tiers.rb @@ -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 diff --git a/db/migrate/20200724094030_create_stopped_sponsorships.rb b/db/migrate/20200724094030_create_stopped_sponsorships.rb new file mode 100644 index 00000000..b639dc4b --- /dev/null +++ b/db/migrate/20200724094030_create_stopped_sponsorships.rb @@ -0,0 +1,11 @@ +class CreateStoppedSponsorships < ActiveRecord::Migration[5.2] + def change + create_table :stopped_sponsorships do |t| + t.integer :amount + t.integer :sponsor_id + t.integer :developer_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724094458_create_wallets.rb b/db/migrate/20200724094458_create_wallets.rb new file mode 100644 index 00000000..eab5a06d --- /dev/null +++ b/db/migrate/20200724094458_create_wallets.rb @@ -0,0 +1,10 @@ +class CreateWallets < ActiveRecord::Migration[5.2] + def change + create_table :wallets do |t| + t.integer :balance + t.integer :user_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200724094729_create_coin_changes.rb b/db/migrate/20200724094729_create_coin_changes.rb new file mode 100644 index 00000000..6999312b --- /dev/null +++ b/db/migrate/20200724094729_create_coin_changes.rb @@ -0,0 +1,13 @@ +class CreateCoinChanges < ActiveRecord::Migration[5.2] + def change + create_table :coin_changes do |t| + t.integer :amount + t.string :description + t.string :reason + t.integer :to_wallet_id + t.integer :from_wallet_id + + t.timestamps + end + end +end diff --git a/db/migrate/20200725025555_create_waitlists.rb b/db/migrate/20200725025555_create_waitlists.rb new file mode 100644 index 00000000..701006e9 --- /dev/null +++ b/db/migrate/20200725025555_create_waitlists.rb @@ -0,0 +1,12 @@ +class CreateWaitlists < ActiveRecord::Migration[5.2] + def change + create_table :waitlists do |t| + t.string :applicant_id + t.string :integer + t.string :reviewer_id + t.string :integer + + t.timestamps + end + end +end diff --git a/db/migrate/20200725025657_create_passed_waitlists.rb b/db/migrate/20200725025657_create_passed_waitlists.rb new file mode 100644 index 00000000..6d8b4b81 --- /dev/null +++ b/db/migrate/20200725025657_create_passed_waitlists.rb @@ -0,0 +1,12 @@ +class CreatePassedWaitlists < ActiveRecord::Migration[5.2] + def change + create_table :passed_waitlists do |t| + t.string :applicant_id + t.string :integer + t.string :reviewer_id + t.string :integer + + t.timestamps + end + end +end diff --git a/spec/controllers/sponsor_tiers_controller_spec.rb b/spec/controllers/sponsor_tiers_controller_spec.rb new file mode 100644 index 00000000..cf7bca64 --- /dev/null +++ b/spec/controllers/sponsor_tiers_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 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 diff --git a/spec/controllers/sponsorships_controller_spec.rb b/spec/controllers/sponsorships_controller_spec.rb new file mode 100644 index 00000000..6098d4d6 --- /dev/null +++ b/spec/controllers/sponsorships_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 SponsorshipsController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Sponsorship. As you add validations to Sponsorship, 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 + # SponsorshipsController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + Sponsorship.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 + sponsorship = Sponsorship.create! valid_attributes + get :show, params: {id: sponsorship.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 + sponsorship = Sponsorship.create! valid_attributes + get :edit, params: {id: sponsorship.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 Sponsorship" do + expect { + post :create, params: {sponsorship: valid_attributes}, session: valid_session + }.to change(Sponsorship, :count).by(1) + end + + it "redirects to the created sponsorship" do + post :create, params: {sponsorship: valid_attributes}, session: valid_session + expect(response).to redirect_to(Sponsorship.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {sponsorship: 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 sponsorship" do + sponsorship = Sponsorship.create! valid_attributes + put :update, params: {id: sponsorship.to_param, sponsorship: new_attributes}, session: valid_session + sponsorship.reload + skip("Add assertions for updated state") + end + + it "redirects to the sponsorship" do + sponsorship = Sponsorship.create! valid_attributes + put :update, params: {id: sponsorship.to_param, sponsorship: valid_attributes}, session: valid_session + expect(response).to redirect_to(sponsorship) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + sponsorship = Sponsorship.create! valid_attributes + put :update, params: {id: sponsorship.to_param, sponsorship: invalid_attributes}, session: valid_session + expect(response).to be_successful + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested sponsorship" do + sponsorship = Sponsorship.create! valid_attributes + expect { + delete :destroy, params: {id: sponsorship.to_param}, session: valid_session + }.to change(Sponsorship, :count).by(-1) + end + + it "redirects to the sponsorships list" do + sponsorship = Sponsorship.create! valid_attributes + delete :destroy, params: {id: sponsorship.to_param}, session: valid_session + expect(response).to redirect_to(sponsorships_url) + end + end + +end diff --git a/spec/helpers/sponsor_tiers_helper_spec.rb b/spec/helpers/sponsor_tiers_helper_spec.rb new file mode 100644 index 00000000..19ce39a7 --- /dev/null +++ b/spec/helpers/sponsor_tiers_helper_spec.rb @@ -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 diff --git a/spec/helpers/sponsorships_helper_spec.rb b/spec/helpers/sponsorships_helper_spec.rb new file mode 100644 index 00000000..229491bf --- /dev/null +++ b/spec/helpers/sponsorships_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the SponsorshipsHelper. For example: +# +# describe SponsorshipsHelper 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 SponsorshipsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/coin_change_spec.rb b/spec/models/coin_change_spec.rb new file mode 100644 index 00000000..313ecf1f --- /dev/null +++ b/spec/models/coin_change_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CoinChange, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/passed_waitlist_spec.rb b/spec/models/passed_waitlist_spec.rb new file mode 100644 index 00000000..5124c945 --- /dev/null +++ b/spec/models/passed_waitlist_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe PassedWaitlist, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/sponsor_tier_spec.rb b/spec/models/sponsor_tier_spec.rb new file mode 100644 index 00000000..3ceab0b6 --- /dev/null +++ b/spec/models/sponsor_tier_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe SponsorTier, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/sponsorship_spec.rb b/spec/models/sponsorship_spec.rb new file mode 100644 index 00000000..d2e58e69 --- /dev/null +++ b/spec/models/sponsorship_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Sponsorship, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/stopped_sponsorship_spec.rb b/spec/models/stopped_sponsorship_spec.rb new file mode 100644 index 00000000..3e4503dd --- /dev/null +++ b/spec/models/stopped_sponsorship_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe StoppedSponsorship, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/waitlist_spec.rb b/spec/models/waitlist_spec.rb new file mode 100644 index 00000000..1b8f43be --- /dev/null +++ b/spec/models/waitlist_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Waitlist, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/wallet_spec.rb b/spec/models/wallet_spec.rb new file mode 100644 index 00000000..768de3cd --- /dev/null +++ b/spec/models/wallet_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Wallet, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/sponsor_tiers_spec.rb b/spec/requests/sponsor_tiers_spec.rb new file mode 100644 index 00000000..55ea2a06 --- /dev/null +++ b/spec/requests/sponsor_tiers_spec.rb @@ -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 diff --git a/spec/requests/sponsorships_spec.rb b/spec/requests/sponsorships_spec.rb new file mode 100644 index 00000000..795504c7 --- /dev/null +++ b/spec/requests/sponsorships_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Sponsorships", type: :request do + describe "GET /sponsorships" do + it "works! (now write some real specs)" do + get sponsorships_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/sponsor_tiers_routing_spec.rb b/spec/routing/sponsor_tiers_routing_spec.rb new file mode 100644 index 00000000..f2c95b1e --- /dev/null +++ b/spec/routing/sponsor_tiers_routing_spec.rb @@ -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 diff --git a/spec/routing/sponsorships_routing_spec.rb b/spec/routing/sponsorships_routing_spec.rb new file mode 100644 index 00000000..4e0cd20b --- /dev/null +++ b/spec/routing/sponsorships_routing_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +RSpec.describe SponsorshipsController, type: :routing do + describe "routing" do + it "routes to #index" do + expect(:get => "/sponsorships").to route_to("sponsorships#index") + end + + it "routes to #new" do + expect(:get => "/sponsorships/new").to route_to("sponsorships#new") + end + + it "routes to #show" do + expect(:get => "/sponsorships/1").to route_to("sponsorships#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/sponsorships/1/edit").to route_to("sponsorships#edit", :id => "1") + end + + + it "routes to #create" do + expect(:post => "/sponsorships").to route_to("sponsorships#create") + end + + it "routes to #update via PUT" do + expect(:put => "/sponsorships/1").to route_to("sponsorships#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/sponsorships/1").to route_to("sponsorships#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/sponsorships/1").to route_to("sponsorships#destroy", :id => "1") + end + end +end diff --git a/spec/views/sponsor_tiers/edit.html.erb_spec.rb b/spec/views/sponsor_tiers/edit.html.erb_spec.rb new file mode 100644 index 00000000..dc11f60a --- /dev/null +++ b/spec/views/sponsor_tiers/edit.html.erb_spec.rb @@ -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 diff --git a/spec/views/sponsor_tiers/index.html.erb_spec.rb b/spec/views/sponsor_tiers/index.html.erb_spec.rb new file mode 100644 index 00000000..56706612 --- /dev/null +++ b/spec/views/sponsor_tiers/index.html.erb_spec.rb @@ -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 diff --git a/spec/views/sponsor_tiers/new.html.erb_spec.rb b/spec/views/sponsor_tiers/new.html.erb_spec.rb new file mode 100644 index 00000000..24ae0a5e --- /dev/null +++ b/spec/views/sponsor_tiers/new.html.erb_spec.rb @@ -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 diff --git a/spec/views/sponsor_tiers/show.html.erb_spec.rb b/spec/views/sponsor_tiers/show.html.erb_spec.rb new file mode 100644 index 00000000..488e7c21 --- /dev/null +++ b/spec/views/sponsor_tiers/show.html.erb_spec.rb @@ -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" do + render + expect(rendered).to match(/2/) + end +end diff --git a/spec/views/sponsorships/edit.html.erb_spec.rb b/spec/views/sponsorships/edit.html.erb_spec.rb new file mode 100644 index 00000000..e676afd1 --- /dev/null +++ b/spec/views/sponsorships/edit.html.erb_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe "sponsorships/edit", type: :view do + before(:each) do + @sponsorship = assign(:sponsorship, Sponsorship.create!( + :amount => 1, + :visible => 1, + :sponsor_id => 1, + :developer_id => 1 + )) + end + + it "renders the edit sponsorship form" do + render + + assert_select "form[action=?][method=?]", sponsorship_path(@sponsorship), "post" do + + assert_select "input[name=?]", "sponsorship[amount]" + + assert_select "input[name=?]", "sponsorship[visible]" + + assert_select "input[name=?]", "sponsorship[sponsor_id]" + + assert_select "input[name=?]", "sponsorship[developer_id]" + end + end +end diff --git a/spec/views/sponsorships/index.html.erb_spec.rb b/spec/views/sponsorships/index.html.erb_spec.rb new file mode 100644 index 00000000..c31533a1 --- /dev/null +++ b/spec/views/sponsorships/index.html.erb_spec.rb @@ -0,0 +1,28 @@ +require 'rails_helper' + +RSpec.describe "sponsorships/index", type: :view do + before(:each) do + assign(:sponsorships, [ + Sponsorship.create!( + :amount => 2, + :visible => 3, + :sponsor_id => 4, + :developer_id => 5 + ), + Sponsorship.create!( + :amount => 2, + :visible => 3, + :sponsor_id => 4, + :developer_id => 5 + ) + ]) + end + + it "renders a list of sponsorships" do + render + assert_select "tr>td", :text => 2.to_s, :count => 2 + assert_select "tr>td", :text => 3.to_s, :count => 2 + assert_select "tr>td", :text => 4.to_s, :count => 2 + assert_select "tr>td", :text => 5.to_s, :count => 2 + end +end diff --git a/spec/views/sponsorships/new.html.erb_spec.rb b/spec/views/sponsorships/new.html.erb_spec.rb new file mode 100644 index 00000000..9c816df1 --- /dev/null +++ b/spec/views/sponsorships/new.html.erb_spec.rb @@ -0,0 +1,27 @@ +require 'rails_helper' + +RSpec.describe "sponsorships/new", type: :view do + before(:each) do + assign(:sponsorship, Sponsorship.new( + :amount => 1, + :visible => 1, + :sponsor_id => 1, + :developer_id => 1 + )) + end + + it "renders new sponsorship form" do + render + + assert_select "form[action=?][method=?]", sponsorships_path, "post" do + + assert_select "input[name=?]", "sponsorship[amount]" + + assert_select "input[name=?]", "sponsorship[visible]" + + assert_select "input[name=?]", "sponsorship[sponsor_id]" + + assert_select "input[name=?]", "sponsorship[developer_id]" + end + end +end diff --git a/spec/views/sponsorships/show.html.erb_spec.rb b/spec/views/sponsorships/show.html.erb_spec.rb new file mode 100644 index 00000000..dffc5a4d --- /dev/null +++ b/spec/views/sponsorships/show.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe "sponsorships/show", type: :view do + before(:each) do + @sponsorship = assign(:sponsorship, Sponsorship.create!( + :amount => 2, + :visible => 3, + :sponsor_id => 4, + :developer_id => 5 + )) + end + + it "renders attributes in
" do + render + expect(rendered).to match(/2/) + expect(rendered).to match(/3/) + expect(rendered).to match(/4/) + expect(rendered).to match(/5/) + end +end