forked from rubyforgood/partner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:rubyforgood/partner
- Loading branch information
Showing
20 changed files
with
239 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,14 @@ If you're getting the error `PG::ConnectionBad: fe_sendauth: no password supplie | |
## Seed the database | ||
From the root of the app, run `bundle exec rails db:seed`. This will create some initial data to use while testing the app and developing new features, including setting up the default user. | ||
|
||
To login, use these default credentials provided in the seeds: | ||
|
||
Verified Organization | ||
Email: [email protected] | ||
Password: password | ||
|
||
Pending Organization | ||
Email: [email protected] | ||
Password: password | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class ApplicationPolicy | ||
attr_reader :user, :record | ||
|
||
def initialize(user, record) | ||
@user = user | ||
@record = record | ||
end | ||
|
||
def index? | ||
false | ||
end | ||
|
||
def show? | ||
false | ||
end | ||
|
||
def create? | ||
false | ||
end | ||
|
||
def new? | ||
create? | ||
end | ||
|
||
def update? | ||
false | ||
end | ||
|
||
def edit? | ||
update? | ||
end | ||
|
||
def destroy? | ||
false | ||
end | ||
|
||
class Scope | ||
attr_reader :user, :scope | ||
|
||
def initialize(user, scope) | ||
@user = user | ||
@scope = scope | ||
end | ||
|
||
def resolve | ||
scope.all | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Authorization for CRUD actions on Partner using Pundit | ||
# | ||
# Pundit relies on current_user | ||
# see `pundit_user` method in partners_controller | ||
# | ||
# Partners can only affect their own records. | ||
# Later may want to admins authorization. | ||
class PartnerPolicy < ApplicationPolicy | ||
def create? | ||
true | ||
end | ||
|
||
def show? | ||
record == user | ||
end | ||
|
||
def update? | ||
record == user | ||
end | ||
|
||
# TODO(chaserx): I think we should prevent deletion until we add a soft delete | ||
def destroy? | ||
false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Authorization for limited CRUD actions on Partner Requests using Pundit | ||
# | ||
# Pundit relies on current_user | ||
# see `pundit_user` method in partner_requests_controller | ||
# | ||
# Partners can only view and create their own records. | ||
class PartnerRequestPolicy < ApplicationPolicy | ||
def index? | ||
true | ||
end | ||
|
||
def create? | ||
record.partner == user | ||
end | ||
|
||
def show? | ||
record.partner == user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
require 'faker' | ||
|
||
# This file should contain all the record creation needed to seed the database with its default values. | ||
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). | ||
# | ||
# Examples: | ||
# | ||
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) | ||
# Character.create(name: 'Luke', movie: movies.first) | ||
|
||
puts "Creating partners..." | ||
puts "Adding an 'approved' partner." | ||
Partner.create( | ||
|
@@ -18,14 +21,27 @@ | |
zip_code: 62558, | ||
website: "http://pawneeindiana.com", | ||
zips_served: 62558, | ||
executive_director_email: "leslie@example.com", | ||
email: "leslie@example.com", | ||
executive_director_email: "org_admin1@example.com", | ||
email: "org_admin1@example.com", | ||
password: "password", | ||
partner_status: "Verified" | ||
) | ||
|
||
puts "Adding a generic 'pending' partner." | ||
pending_user_name = Faker::Name.name | ||
Partner.create( | ||
email: "[email protected]", | ||
executive_director_name: pending_user_name, | ||
program_contact_name: pending_user_name, | ||
name: "County Diaper Bank", | ||
address1: Faker::Address.street_address, | ||
address2: "", | ||
city: Faker::Address.city, | ||
state: Faker::Address.state_abbr, | ||
zip_code: Faker::Address.zip, | ||
website: Faker::Internet.domain_name, | ||
zips_served: Faker::Address.zip, | ||
executive_director_email: "[email protected]", | ||
email: "[email protected]", | ||
password: "password" | ||
) | ||
puts "Done creating partners." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe PartnersController, type: :controller do | ||
login_partner | ||
|
||
describe "GET #new" do | ||
it "returns http success" do | ||
get :new | ||
expect(response).to have_http_status(200) | ||
end | ||
end | ||
|
||
describe "Get #approve" do | ||
it "should redirect to partner" do | ||
@partner = create(:partner) | ||
get :approve, params: { partner_id: @partner.id } | ||
expect(response).to redirect_to(@partner) | ||
end | ||
end | ||
|
||
describe "Post #create" do | ||
it "creates a new partner" do | ||
expect do | ||
print(FactoryBot.attributes_for(:partner)) | ||
post :create, params: { partner: FactoryBot.attributes_for(:partner) } | ||
end.to change(Partner, :count).by(0) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.