mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-25 09:19:15 -04:00
Compare commits
15 Commits
release82
...
openfarm-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ec6c7cd83 | ||
|
|
f872957782 | ||
|
|
8122a748ee | ||
|
|
b1473c4d8f | ||
|
|
e5303ce1bb | ||
|
|
63f861afb3 | ||
|
|
5c15997d64 | ||
|
|
8011bb1a4c | ||
|
|
5259b449c2 | ||
|
|
c67f561881 | ||
|
|
cb7ec140f4 | ||
|
|
269d66a0bd | ||
|
|
6dc6422805 | ||
|
|
48ec11a96e | ||
|
|
2d62413341 |
@@ -1,32 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class BlocksController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
skip_load_resource only: :create
|
||||
|
||||
def create
|
||||
@block = current_member.blocks.build(blocked: Member.find(params[:blocked]))
|
||||
|
||||
if @block.save
|
||||
flash[:notice] = "Blocked #{@block.blocked.login_name}"
|
||||
else
|
||||
flash[:error] = "Already blocking or error while blocking."
|
||||
end
|
||||
redirect_back fallback_location: root_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@block = current_member.blocks.find(params[:id])
|
||||
@unblocked = @block.blocked
|
||||
@block.destroy
|
||||
|
||||
flash[:notice] = "Unblocked #{@unblocked.login_name}"
|
||||
redirect_to @unblocked
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def block_params
|
||||
params.permit(:id, :blocked)
|
||||
end
|
||||
end
|
||||
@@ -27,21 +27,10 @@ class MessagesController < ApplicationController
|
||||
def create
|
||||
if params[:conversation_id].present?
|
||||
@conversation = Mailboxer::Conversation.find(params[:conversation_id])
|
||||
# Check if any of the recipients have blocked the sender
|
||||
if @conversation.recipients.any? { |recipient| recipient.already_blocking?(current_member) }
|
||||
flash[:error] = "You cannot reply to this conversation because one of the recipients has blocked you."
|
||||
redirect_to conversation_path(@conversation)
|
||||
return
|
||||
end
|
||||
current_member.reply_to_conversation(@conversation, params[:body])
|
||||
redirect_to conversation_path(@conversation)
|
||||
else
|
||||
recipient = Member.find(params[:recipient_id])
|
||||
if recipient.already_blocking?(current_member)
|
||||
flash[:error] = "You cannot send a message to a member who has blocked you."
|
||||
redirect_back fallback_location: root_path
|
||||
return
|
||||
end
|
||||
body = params[:body]
|
||||
subject = params[:subject]
|
||||
@conversation = current_member.send_message(recipient, body, subject)
|
||||
|
||||
@@ -79,7 +79,6 @@ class Ability
|
||||
can :manage, CropCompanion
|
||||
can :manage, ScientificName
|
||||
can :manage, AlternateName
|
||||
can :openfarm, Crop
|
||||
can :gbif, Crop
|
||||
end
|
||||
|
||||
@@ -164,12 +163,6 @@ class Ability
|
||||
can :destroy, Follow
|
||||
cannot :destroy, Follow, followed_id: member.id # can't unfollow yourself
|
||||
|
||||
# blocking/unblocking permissions
|
||||
can :create, Block
|
||||
cannot :create, Block, blocked_id: member.id # can't block yourself
|
||||
|
||||
can :destroy, Block, blocker_id: member.id # can only unblock your own blocks
|
||||
|
||||
cannot :create, GardenType
|
||||
cannot :update, GardenType
|
||||
cannot :destroy, GardenType
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Block < ApplicationRecord
|
||||
belongs_to :blocker, class_name: "Member"
|
||||
belongs_to :blocked, class_name: "Member"
|
||||
|
||||
validates :blocker_id, uniqueness: { scope: :blocked_id }
|
||||
|
||||
after_create :destroy_follow_relationship
|
||||
|
||||
private
|
||||
|
||||
def destroy_follow_relationship
|
||||
# Destroy the follow relationship in both directions
|
||||
Follow.where(follower: blocker, followed: blocked).destroy_all
|
||||
Follow.where(follower: blocked, followed: blocker).destroy_all
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,6 @@ class Comment < ApplicationRecord
|
||||
belongs_to :author, class_name: 'Member', inverse_of: :comments
|
||||
belongs_to :commentable, polymorphic: true, counter_cache: true
|
||||
# validates :body, presence: true
|
||||
validate :author_is_not_blocked
|
||||
|
||||
scope :post_order, -> { order(created_at: :asc) } # for display on post page
|
||||
|
||||
@@ -26,13 +25,4 @@ class Comment < ApplicationRecord
|
||||
def to_s
|
||||
"#{author.login_name} commented on #{commentable.subject}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def author_is_not_blocked
|
||||
return unless author
|
||||
if commentable.author.already_blocking?(author)
|
||||
errors.add(:base, "You cannot comment on a post of a member who has blocked you.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ class Crop < ApplicationRecord
|
||||
has_paper_trail
|
||||
extend FriendlyId
|
||||
include PhotoCapable
|
||||
include OpenFarmData
|
||||
include GbifData
|
||||
include SearchCrops
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ class Follow < ApplicationRecord
|
||||
belongs_to :follower, class_name: "Member", inverse_of: :follows
|
||||
belongs_to :followed, class_name: "Member", inverse_of: :inverse_follows
|
||||
validates :follower_id, uniqueness: { scope: :followed_id }
|
||||
validate :follower_is_not_blocked
|
||||
|
||||
after_create do
|
||||
Notification.create(
|
||||
@@ -15,13 +14,4 @@ class Follow < ApplicationRecord
|
||||
notifiable: self
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def follower_is_not_blocked
|
||||
return unless follower
|
||||
if followed.already_blocking?(follower)
|
||||
errors.add(:base, "You cannot follow a member who has blocked you.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,23 +5,4 @@ class Like < ApplicationRecord
|
||||
belongs_to :likeable, polymorphic: true, counter_cache: true, touch: true
|
||||
validates :member, :likeable, presence: true
|
||||
validates :member, uniqueness: { scope: :likeable }
|
||||
validate :member_is_not_blocked
|
||||
|
||||
def likeable_author
|
||||
if likeable.respond_to?(:author)
|
||||
likeable.author
|
||||
elsif likeable.respond_to?(:owner)
|
||||
likeable.owner
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def member_is_not_blocked
|
||||
return unless member
|
||||
author = likeable_author
|
||||
if author && author.already_blocking?(member)
|
||||
errors.add(:base, "You cannot like content of a member who has blocked you.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,15 +52,6 @@ class Member < ApplicationRecord
|
||||
has_many :followed, through: :follows
|
||||
has_many :followers, through: :inverse_follows, source: :follower
|
||||
|
||||
#
|
||||
# Blocking other members
|
||||
has_many :blocks, class_name: "Block", foreign_key: "blocker_id", dependent: :destroy,
|
||||
inverse_of: :blocker
|
||||
has_many :inverse_blocks, class_name: "Block", foreign_key: "blocked_id",
|
||||
dependent: :destroy, inverse_of: :blocked
|
||||
has_many :blocked_members, through: :blocks, source: :blocked
|
||||
has_many :blockers, through: :inverse_blocks, source: :blocker
|
||||
|
||||
#
|
||||
# Global data records this member created
|
||||
has_many :requested_crops, class_name: 'Crop', foreign_key: 'requester_id', dependent: :nullify,
|
||||
@@ -188,12 +179,4 @@ class Member < ApplicationRecord
|
||||
def get_follow(member)
|
||||
follows.find_by(followed_id: member.id) if already_following?(member)
|
||||
end
|
||||
|
||||
def already_blocking?(member)
|
||||
blocks.exists?(blocked_id: member.id)
|
||||
end
|
||||
|
||||
def get_block(member)
|
||||
blocks.find_by(blocked_id: member.id) if already_blocking?(member)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -126,12 +126,9 @@ class GbifService
|
||||
|
||||
gbif_record = fetch(gbif_usage_key)
|
||||
if gbif_record.present?
|
||||
# crop.update! openfarm_data: gbif_record.fetch('data', false)
|
||||
# save_companions(crop, gbif_record)
|
||||
save_photos(crop, gbif_usage_key)
|
||||
else
|
||||
Rails.logger.debug "\tcrop not found on GBIF"
|
||||
# crop.update!(openfarm_data: false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
- @forums.each do |forum|
|
||||
%h2= forum
|
||||
%p= forum.description
|
||||
%p
|
||||
= localize_plural(forum.posts, Post)
|
||||
|
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
- if current_member && current_member != member # must be logged in, can't follow yourself
|
||||
- block = current_member.get_block(member)
|
||||
- follow = current_member.get_follow(member)
|
||||
- if !block && !follow && can?(:create, Follow) # not already following, and not blocking
|
||||
- if !follow && can?(:create, Follow) # not already following
|
||||
= link_to 'Follow', follows_path(followed: member), method: :post, class: 'btn btn-block btn-success'
|
||||
- if follow && can?(:destroy, follow) # already following
|
||||
= link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-block'
|
||||
- if !block && can?(:create, Block) # not already blocking
|
||||
= link_to 'Block', blocks_path(blocked: member), method: :post, class: 'btn btn-block btn-danger'
|
||||
- if block && can?(:destroy, block) # already blocking
|
||||
= link_to 'Unblock', block_path(block), method: :delete, class: 'btn btn-block'
|
||||
= link_to 'Unfollow', follow_path(follow), method: :delete, class: 'btn btn-block'
|
||||
@@ -105,7 +105,6 @@ Rails.application.routes.draw do
|
||||
resources :forums
|
||||
|
||||
resources :follows, only: %i(create destroy)
|
||||
resources :blocks, only: %i(create destroy)
|
||||
|
||||
post 'likes' => 'likes#create'
|
||||
delete 'likes' => 'likes#destroy'
|
||||
@@ -122,7 +121,6 @@ Rails.application.routes.draw do
|
||||
|
||||
resources :follows
|
||||
get 'followers' => 'follows#followers'
|
||||
resources :blocks, only: %i(create destroy)
|
||||
end
|
||||
|
||||
resources :messages
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateBlocks < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :blocks do |t|
|
||||
t.references :blocker, foreign_key: { to_table: :members }
|
||||
t.references :blocked, foreign_key: { to_table: :members }
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :blocks, [:blocker_id, :blocked_id], unique: true
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
db/schema.rb
@@ -384,16 +384,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_12_01_045000) do
|
||||
t.index ["member_id"], name: "index_authentications_on_member_id"
|
||||
end
|
||||
|
||||
create_table "blocks", force: :cascade do |t|
|
||||
t.bigint "blocker_id"
|
||||
t.bigint "blocked_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["blocked_id"], name: "index_blocks_on_blocked_id"
|
||||
t.index ["blocker_id", "blocked_id"], name: "index_blocks_on_blocker_id_and_blocked_id", unique: true
|
||||
t.index ["blocker_id"], name: "index_blocks_on_blocker_id"
|
||||
end
|
||||
|
||||
create_table "comfy_cms_categories", id: :serial, force: :cascade do |t|
|
||||
t.integer "site_id", null: false
|
||||
t.string "label", null: false
|
||||
@@ -982,8 +972,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_12_01_045000) do
|
||||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "blocks", "members", column: "blocked_id"
|
||||
add_foreign_key "blocks", "members", column: "blocker_id"
|
||||
add_foreign_key "harvests", "plantings"
|
||||
add_foreign_key "mailboxer_conversation_opt_outs", "mailboxer_conversations", column: "conversation_id", name: "mb_opt_outs_on_conversations_id"
|
||||
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", column: "conversation_id", name: "notifications_on_conversation_id"
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ForumsController do
|
||||
let(:admin) { create(:admin_member) }
|
||||
let(:member) { create(:member) }
|
||||
let(:forum) { create(:forum) }
|
||||
|
||||
describe "GET #index" do
|
||||
it "returns a success response" do
|
||||
get :index
|
||||
expect(response).to be_successful
|
||||
end
|
||||
|
||||
it "assigns @forums" do
|
||||
forum # create forum
|
||||
get :index
|
||||
expect(assigns(:forums)).to include(forum)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns a success response" do
|
||||
get :show, params: { id: forum.to_param }
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
context "as an admin" do
|
||||
before { sign_in admin }
|
||||
|
||||
describe "GET #new" do
|
||||
it "returns a success response" do
|
||||
get :new
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #edit" do
|
||||
it "returns a success response" do
|
||||
get :edit, params: { id: forum.to_param }
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
context "with valid params" do
|
||||
let(:valid_attributes) { { name: "New Forum", description: "A new forum", owner_id: admin.id } }
|
||||
|
||||
it "creates a new Forum" do
|
||||
expect {
|
||||
post :create, params: { forum: valid_attributes }
|
||||
}.to change(Forum, :count).by(1)
|
||||
end
|
||||
|
||||
it "redirects to the created forum" do
|
||||
post :create, params: { forum: valid_attributes }
|
||||
expect(response).to redirect_to(Forum.last)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT #update" do
|
||||
context "with valid params" do
|
||||
let(:new_attributes) { { name: "Updated Name" } }
|
||||
|
||||
it "updates the requested forum" do
|
||||
put :update, params: { id: forum.to_param, forum: new_attributes }
|
||||
forum.reload
|
||||
expect(forum.name).to eq("Updated Name")
|
||||
end
|
||||
|
||||
it "redirects to the forum" do
|
||||
put :update, params: { id: forum.to_param, forum: new_attributes }
|
||||
expect(response).to redirect_to(forum)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE #destroy" do
|
||||
it "destroys the requested forum" do
|
||||
forum # ensure forum exists
|
||||
expect {
|
||||
delete :destroy, params: { id: forum.to_param }
|
||||
}.to change(Forum, :count).by(-1)
|
||||
end
|
||||
|
||||
it "redirects to the forums list" do
|
||||
delete :destroy, params: { id: forum.to_param }
|
||||
expect(response).to redirect_to(forums_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "as a regular member" do
|
||||
before { sign_in member }
|
||||
|
||||
describe "GET #new" do
|
||||
it "denies access" do
|
||||
get :new
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
it "denies access" do
|
||||
post :create, params: { forum: { name: "Forbidden" } }
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,47 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "Forums usage", :js do
|
||||
let!(:forum) { create(:forum, name: "General Discussion", description: "Talk about anything") }
|
||||
let(:member) { create(:member) }
|
||||
|
||||
describe "browsing forums" do
|
||||
it "shows the list of forums" do
|
||||
visit forums_path
|
||||
expect(page).to have_content("General Discussion")
|
||||
expect(page).to have_content("Talk about anything")
|
||||
end
|
||||
end
|
||||
|
||||
describe "viewing a forum" do
|
||||
let!(:post) { create(:post, forum: forum, subject: "Hello World", author: member) }
|
||||
|
||||
it "shows forum details and posts" do
|
||||
visit forum_path(forum)
|
||||
expect(page).to have_css("h1", text: "General Discussion")
|
||||
expect(page).to have_content("Talk about anything")
|
||||
expect(page).to have_content("Hello World")
|
||||
expect(page).to have_link("Post something")
|
||||
end
|
||||
end
|
||||
|
||||
describe "starting a new post from a forum" do
|
||||
include_context 'signed in member'
|
||||
|
||||
it "pre-fills the forum when creating a new post" do
|
||||
visit forum_path(forum)
|
||||
click_link "Post something"
|
||||
|
||||
expect(page).to have_current_path(new_post_path(forum_id: forum.id))
|
||||
expect(page).to have_content("This post will be posted in the forum #{forum.name}")
|
||||
|
||||
fill_in "post_subject", with: "My New Post"
|
||||
fill_in "post_body", with: "Content of my post"
|
||||
click_button "Post"
|
||||
|
||||
expect(page).to have_content("Post was successfully created")
|
||||
expect(Post.last.forum).to eq(forum)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,72 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe "blocks", :js do
|
||||
context "when signed in" do
|
||||
include_context 'signed in member'
|
||||
let(:other_member) { create(:member) }
|
||||
|
||||
it "your profile doesn't have a block button" do
|
||||
visit member_path(member)
|
||||
expect(page).to have_no_link "Block"
|
||||
expect(page).to have_no_link "Unblock"
|
||||
end
|
||||
|
||||
context "blocking another member" do
|
||||
before { visit member_path(other_member) }
|
||||
|
||||
it "has a block button" do
|
||||
expect(page).to have_link "Block", href: blocks_path(blocked: other_member.slug)
|
||||
end
|
||||
|
||||
it "has correct message and unblock button" do
|
||||
click_link 'Block'
|
||||
expect(page).to have_content "Blocked #{other_member.login_name}"
|
||||
expect(page).to have_link "Unblock", href: block_path(member.get_block(other_member))
|
||||
end
|
||||
|
||||
it "has correct message and block button after unblock" do
|
||||
click_link 'Block'
|
||||
click_link 'Unblock'
|
||||
expect(page).to have_content "Unblocked #{other_member.login_name}"
|
||||
visit member_path(other_member) # unblocking redirects to root
|
||||
expect(page).to have_link "Block", href: blocks_path(blocked: other_member.slug)
|
||||
end
|
||||
|
||||
context "when a member is blocked" do
|
||||
before do
|
||||
click_link 'Block'
|
||||
end
|
||||
|
||||
it "prevents following" do
|
||||
visit member_path(other_member)
|
||||
expect(page).to have_no_link "Follow"
|
||||
end
|
||||
|
||||
xit "prevents messaging" do
|
||||
visit new_message_path(recipient_id: other_member.id)
|
||||
fill_in "Subject", with: "Test message"
|
||||
fill_in "Body", with: "Test message body"
|
||||
click_button "Send message"
|
||||
expect(page).to have_content "You cannot send a message to a member who has blocked you."
|
||||
end
|
||||
|
||||
xit "prevents commenting" do
|
||||
post = create(:post, author: other_member)
|
||||
visit post_path(post)
|
||||
fill_in "comment_body", with: "Test comment"
|
||||
click_button "Post Comment"
|
||||
expect(page).to have_content "You cannot comment on a post of a member who has blocked you."
|
||||
end
|
||||
|
||||
xit "prevents liking" do
|
||||
post = create(:post, author: other_member)
|
||||
visit post_path(post)
|
||||
click_link "Like"
|
||||
expect(page).to have_content "You cannot like content of a member who has blocked you."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -23,17 +23,6 @@ describe "follows", :js do
|
||||
expect(page).to have_no_link "Unfollow"
|
||||
end
|
||||
|
||||
context "when the other member is blocked" do
|
||||
before do
|
||||
member.blocks.create(blocked: other_member)
|
||||
visit member_path(other_member)
|
||||
end
|
||||
|
||||
it "does not have a follow button" do
|
||||
expect(page).to have_no_link "Follow"
|
||||
end
|
||||
end
|
||||
|
||||
context "following another member" do
|
||||
before { visit member_path(other_member) }
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ require 'rails_helper'
|
||||
|
||||
describe PhotosHelper do
|
||||
let(:crop) { create(:crop) }
|
||||
let(:crop_photo_of) { create(:photo, source: 'openfarm') }
|
||||
let(:crop_photo_flickr) { create(:photo, source: 'flickr') }
|
||||
|
||||
let(:garden) { create(:garden) }
|
||||
|
||||
@@ -77,90 +77,6 @@ describe Ability do
|
||||
end
|
||||
end
|
||||
|
||||
context 'plantings' do
|
||||
let(:approved_crop) { create(:crop, approval_status: 'approved') }
|
||||
let(:unapproved_crop) { create(:crop, approval_status: 'unapproved') }
|
||||
let(:garden) { create(:garden, owner: member) }
|
||||
let(:planting) { create(:planting, garden: garden, crop: approved_crop, owner: member) }
|
||||
let(:other_planting) { create(:planting, crop: approved_crop) }
|
||||
let(:planting_with_unapproved_crop) { create(:planting, garden: garden, crop: unapproved_crop, owner: member) }
|
||||
|
||||
it 'can create a planting' do
|
||||
ability.should be_able_to(:create, Planting)
|
||||
end
|
||||
|
||||
it 'can manage their own planting with an approved crop' do
|
||||
ability.should be_able_to(:update, planting)
|
||||
ability.should be_able_to(:destroy, planting)
|
||||
end
|
||||
|
||||
xit "can't manage their own planting with an unapproved crop" do
|
||||
ability.should_not be_able_to(:update, planting_with_unapproved_crop)
|
||||
ability.should_not be_able_to(:destroy, planting_with_unapproved_crop)
|
||||
end
|
||||
|
||||
it "can't manage another member's planting" do
|
||||
ability.should_not be_able_to(:update, other_planting)
|
||||
ability.should_not be_able_to(:destroy, other_planting)
|
||||
end
|
||||
|
||||
it 'can transplant their own planting' do
|
||||
ability.should be_able_to(:transplant, planting)
|
||||
end
|
||||
|
||||
context 'garden collaborator' do
|
||||
let(:garden) { create(:garden) }
|
||||
let(:planting_in_garden) { create(:planting, garden:, crop: approved_crop, owner: garden.owner) }
|
||||
|
||||
before do
|
||||
garden.garden_collaborators.create(member:)
|
||||
end
|
||||
|
||||
it 'can manage plantings in a garden they collaborate on' do
|
||||
ability.should be_able_to(:update, planting_in_garden)
|
||||
ability.should be_able_to(:destroy, planting_in_garden)
|
||||
end
|
||||
|
||||
it 'can transplant a planting in a garden they collaborate on' do
|
||||
ability.should be_able_to(:transplant, planting_in_garden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'harvests' do
|
||||
let(:harvest) { create(:harvest, owner: member) }
|
||||
let(:other_harvest) { create(:harvest) }
|
||||
|
||||
it 'can create a harvest' do
|
||||
ability.should be_able_to(:create, Harvest)
|
||||
end
|
||||
|
||||
it 'can manage their own harvest' do
|
||||
ability.should be_able_to(:update, harvest)
|
||||
ability.should be_able_to(:destroy, harvest)
|
||||
end
|
||||
|
||||
it "can't manage another member's harvest" do
|
||||
ability.should_not be_able_to(:update, other_harvest)
|
||||
ability.should_not be_able_to(:destroy, other_harvest)
|
||||
end
|
||||
|
||||
context 'garden collaborator' do
|
||||
let(:garden) { create(:garden) }
|
||||
let(:planting_in_garden) { create(:planting, garden:, owner: garden.owner) }
|
||||
let(:harvest_in_garden) { create(:harvest, planting: planting_in_garden, owner: planting_in_garden.owner) }
|
||||
|
||||
before do
|
||||
garden.garden_collaborators.create(member:)
|
||||
end
|
||||
|
||||
it 'can manage harvests in a garden they collaborate on' do
|
||||
ability.should be_able_to(:update, harvest_in_garden)
|
||||
ability.should be_able_to(:destroy, harvest_in_garden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'plant parts' do
|
||||
let(:plant_part) { create(:plant_part) }
|
||||
|
||||
@@ -226,111 +142,4 @@ describe Ability do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'activities' do
|
||||
let(:activity) { create(:activity, owner: member) }
|
||||
let(:other_activity) { create(:activity) }
|
||||
|
||||
it 'can create an activity' do
|
||||
ability.should be_able_to(:create, Activity)
|
||||
end
|
||||
|
||||
it 'can manage their own activity' do
|
||||
ability.should be_able_to(:update, activity)
|
||||
ability.should be_able_to(:destroy, activity)
|
||||
end
|
||||
|
||||
it "can't manage another member's activity" do
|
||||
ability.should_not be_able_to(:update, other_activity)
|
||||
ability.should_not be_able_to(:destroy, other_activity)
|
||||
end
|
||||
|
||||
context 'garden collaborator' do
|
||||
let(:garden) { create(:garden) }
|
||||
let(:activity_in_garden) { create(:activity, garden:) }
|
||||
|
||||
before do
|
||||
garden.garden_collaborators.create(member:)
|
||||
end
|
||||
|
||||
it 'can manage activities in a garden they collaborate on' do
|
||||
ability.should be_able_to(:update, activity_in_garden)
|
||||
ability.should be_able_to(:destroy, activity_in_garden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'seeds' do
|
||||
let(:seed) { create(:seed, owner: member) }
|
||||
let(:other_seed) { create(:seed) }
|
||||
|
||||
it 'can create a seed' do
|
||||
ability.should be_able_to(:create, Seed)
|
||||
end
|
||||
|
||||
it 'can manage their own seed' do
|
||||
ability.should be_able_to(:update, seed)
|
||||
ability.should be_able_to(:destroy, seed)
|
||||
end
|
||||
|
||||
it "can't manage another member's seed" do
|
||||
ability.should_not be_able_to(:update, other_seed)
|
||||
ability.should_not be_able_to(:destroy, other_seed)
|
||||
end
|
||||
end
|
||||
|
||||
context 'comments' do
|
||||
let(:comment) { create(:comment, author: member) }
|
||||
let(:other_comment) { create(:comment) }
|
||||
|
||||
it 'can create a comment' do
|
||||
ability.should be_able_to(:create, Comment)
|
||||
end
|
||||
|
||||
it 'can manage their own comment' do
|
||||
ability.should be_able_to(:update, comment)
|
||||
ability.should be_able_to(:destroy, comment)
|
||||
end
|
||||
|
||||
it "can't manage another member's comment" do
|
||||
ability.should_not be_able_to(:update, other_comment)
|
||||
ability.should_not be_able_to(:destroy, other_comment)
|
||||
end
|
||||
end
|
||||
|
||||
context 'photos' do
|
||||
let(:photo) { create(:photo, owner: member) }
|
||||
let(:other_photo) { create(:photo) }
|
||||
|
||||
it 'can create a photo' do
|
||||
ability.should be_able_to(:create, Photo)
|
||||
end
|
||||
|
||||
it 'can manage their own photo' do
|
||||
ability.should be_able_to(:update, photo)
|
||||
ability.should be_able_to(:destroy, photo)
|
||||
end
|
||||
|
||||
it "can't manage another member's photo" do
|
||||
ability.should_not be_able_to(:update, other_photo)
|
||||
ability.should_not be_able_to(:destroy, other_photo)
|
||||
end
|
||||
end
|
||||
|
||||
context 'likes' do
|
||||
let(:like) { create(:like, member:) }
|
||||
let(:other_like) { create(:like) }
|
||||
|
||||
it 'can create a like' do
|
||||
ability.should be_able_to(:create, Like)
|
||||
end
|
||||
|
||||
it 'can destroy their own like' do
|
||||
ability.should be_able_to(:destroy, like)
|
||||
end
|
||||
|
||||
it "can't destroy another member's like" do
|
||||
ability.should_not be_able_to(:destroy, other_like)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,21 +41,6 @@ describe Comment do
|
||||
end
|
||||
end
|
||||
|
||||
context "when the post author has blocked the comment author" do
|
||||
let(:post_author) { create(:member) }
|
||||
let(:comment_author) { create(:member) }
|
||||
let(:post) { create(:post, author: post_author) }
|
||||
|
||||
before do
|
||||
post_author.blocks.create(blocked: comment_author)
|
||||
end
|
||||
|
||||
it "is not valid" do
|
||||
comment = build(:comment, commentable: post, author: comment_author)
|
||||
expect(comment).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "ordering" do
|
||||
before do
|
||||
@m = create(:member)
|
||||
|
||||
@@ -63,21 +63,6 @@ describe Like do
|
||||
expect(Like.all).not_to include like
|
||||
end
|
||||
|
||||
context "when the likeable author has blocked the member" do
|
||||
let(:likeable_author) { create(:member) }
|
||||
let(:post_author) { create(:member) }
|
||||
let(:post) { create(:post, author: likeable_author) }
|
||||
|
||||
before do
|
||||
likeable_author.blocks.create(blocked: member)
|
||||
end
|
||||
|
||||
it "is not valid" do
|
||||
like = build(:like, likeable: post, member: member)
|
||||
expect(like).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it 'liked_by_members_names' do
|
||||
expect(post.liked_by_members_names).to eq []
|
||||
Like.create(member:, likeable: post)
|
||||
|
||||
@@ -3,53 +3,11 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "Forums" do
|
||||
let(:admin) { create(:admin_member) }
|
||||
let(:forum) { create(:forum) }
|
||||
|
||||
describe "GET /forums" do
|
||||
it "returns a successful response" do
|
||||
it "works! (now write some real specs)" do
|
||||
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
||||
get forums_path
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "returns JSON when requested" do
|
||||
get forums_path(format: :json)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.content_type).to include("application/json")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /forums/:id" do
|
||||
it "returns a successful response" do
|
||||
get forum_path(forum)
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "returns JSON when requested" do
|
||||
get forum_path(forum, format: :json)
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.content_type).to include("application/json")
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /forums" do
|
||||
context "as an admin" do
|
||||
before { sign_in admin }
|
||||
|
||||
it "creates a new forum" do
|
||||
expect {
|
||||
post forums_path, params: { forum: { name: "New Request Forum", description: "Desc", owner_id: admin.id } }
|
||||
}.to change(Forum, :count).by(1)
|
||||
expect(response).to redirect_to(forum_path(Forum.last))
|
||||
end
|
||||
end
|
||||
|
||||
context "as a guest" do
|
||||
it "redirects to sign in or denies access" do
|
||||
post forums_path, params: { forum: { name: "New Request Forum", description: "Desc" } }
|
||||
# Depending on CanCan/Devise setup, it might be a redirect to login or root
|
||||
expect(response).to redirect_to(new_member_session_path).or redirect_to(root_path)
|
||||
end
|
||||
response.status.should be(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user