mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-12 01:36:26 -04:00
adds more basic specs
This commit is contained in:
@@ -6,7 +6,7 @@ class Container < ActiveRecord::Base
|
||||
|
||||
def subtitler(container)
|
||||
num = container.gardens.uniq.count
|
||||
s = (num > 1 || num == 0) ? "s are" : " is"
|
||||
return "#{num.to_s} garden#{s} using this container"
|
||||
s = num > 1 || num.zero? ? "s are" : " is"
|
||||
"#{num} garden#{s} using this container"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,3 @@
|
||||
= render 'shared/buttons/edit', path: edit_container_path(container)
|
||||
.pull-right
|
||||
= render 'shared/buttons/delete', path: container_path(container)
|
||||
|
||||
- if can? :create, container
|
||||
= link_to new_container_path, class: 'btn btn-default btn-xs' do
|
||||
%span.glyphicon.glyphicon-grain{ title: "Create new container" }
|
||||
Create new container
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
%li= link_to t('.seeds'), seeds_path
|
||||
%li= link_to t('.plantings'), plantings_path
|
||||
%li= link_to t('.harvests'), harvests_path
|
||||
%li= link_to t('.containers'), containers_path
|
||||
%li.dropdown<
|
||||
%a.dropdown-toggle{ 'data-toggle': 'dropdown', href: members_path }
|
||||
= t('.community')
|
||||
|
||||
@@ -144,6 +144,8 @@ en:
|
||||
browse_members: Browse Members
|
||||
community: Community
|
||||
community_map: Community Map
|
||||
container: Container
|
||||
containers: Containers
|
||||
crop_wrangling: Crop Wrangling
|
||||
crops: Crops
|
||||
current_memberlogin_name: "%{current_memberlogin_name}"
|
||||
@@ -229,6 +231,7 @@ en:
|
||||
planting: Please sign in or sign up to plant something.
|
||||
post: Please sign in or sign up to post.
|
||||
seed: Please sign in or sign up to add seeds.
|
||||
container: Not authorized. Only admins can create containers.
|
||||
manage:
|
||||
all: Not authorized to %{action} %{subject}.
|
||||
read:
|
||||
|
||||
@@ -3,9 +3,88 @@ require 'rails_helper'
|
||||
RSpec.describe ContainersController, type: :controller do
|
||||
include Devise::Test::ControllerHelpers
|
||||
let(:valid_params) { { description: 'My second Container' } }
|
||||
|
||||
let(:container) { FactoryBot.create :container }
|
||||
|
||||
let(:member) { FactoryBot.create(:member) }
|
||||
let(:admin_member) { FactoryBot.create(:admin) }
|
||||
|
||||
context "when not signed in" do
|
||||
describe 'GET new' do
|
||||
before { get :new, id: container.to_param }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'PUT create' do
|
||||
before { put :create, container: valid_params }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'changing existing records' do
|
||||
before do
|
||||
allow(Container).to receive(:find).and_return(:container)
|
||||
expect(container).not_to receive(:save)
|
||||
expect(container).not_to receive(:save!)
|
||||
expect(container).not_to receive(:update)
|
||||
expect(container).not_to receive(:update!)
|
||||
expect(container).not_to receive(:destroy)
|
||||
end
|
||||
|
||||
describe 'GET edit' do
|
||||
before { get :edit, id: container.to_param }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'POST update' do
|
||||
before { post :update, id: container.to_param, container: valid_params }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'DELETE' do
|
||||
before { delete :destroy, id: container.to_param, params: { container: valid_params } }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when signed in as a member" do
|
||||
before(:each) { sign_in member }
|
||||
|
||||
let!(:member) { FactoryBot.create(:member) }
|
||||
|
||||
describe "for any container" do
|
||||
let(:any_container) { double('container') }
|
||||
|
||||
before do
|
||||
expect(Container).to receive(:find).and_return(:any_container)
|
||||
expect(any_container).not_to receive(:save)
|
||||
expect(any_container).not_to receive(:save!)
|
||||
expect(any_container).not_to receive(:update)
|
||||
expect(any_container).not_to receive(:update!)
|
||||
expect(any_container).not_to receive(:destroy)
|
||||
end
|
||||
|
||||
describe 'GET edit' do
|
||||
before { get :edit, id: any_container.to_param }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'POST update' do
|
||||
before { post :update, id: any_container.to_param, container: valid_params }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
|
||||
describe 'DELETE' do
|
||||
before { delete :destroy, id: any_container.to_param, params: { container: valid_params } }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe Container do
|
||||
let(:owner) { FactoryBot.create(:member) }
|
||||
let(:garden) { FactoryBot.create(:garden, owner: owner, name: 'Free Carrots') }
|
||||
let(:container) { FactoryBot.create(:container, description: "fake hole in the ground") }
|
||||
|
||||
it "should have a description" do
|
||||
container = FactoryBot.build(:container, description: "organic")
|
||||
container.should be_valid
|
||||
@@ -17,7 +21,17 @@ describe Container do
|
||||
end
|
||||
|
||||
it "doesn't allow a description with only spaces" do
|
||||
garden = FactoryBot.build(:container, description: " ")
|
||||
garden.should_not be_valid
|
||||
container = FactoryBot.build(:container, description: " ")
|
||||
container.should_not be_valid
|
||||
end
|
||||
|
||||
it "destroys plots when deleted" do
|
||||
container = FactoryBot.create(:container, description: "Massive Flower Pot")
|
||||
@plot1 = FactoryBot.create(:plot, garden: garden, container: container)
|
||||
@plot2 = FactoryBot.create(:plot, garden: garden, container: container)
|
||||
container.plots.size.should eq(2)
|
||||
all = Plot.count
|
||||
container.destroy
|
||||
Plot.count.should eq(all - 2)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,14 +2,16 @@ require 'rails_helper'
|
||||
|
||||
describe Plot do
|
||||
let(:owner) { FactoryBot.create(:member) }
|
||||
let(:garden) { FactoryBot.create(:garden, owner: owner, name: "Magic Beanstalk") }
|
||||
let(:container) { FactoryBot.create(:container, description: "vertical") }
|
||||
let(:garden) { FactoryBot.create(:garden) }
|
||||
let(:container) { FactoryBot.create(:container) }
|
||||
let(:plot) { FactoryBot.create(:plot, garden: garden, container: container) }
|
||||
|
||||
context "has valid attributes" do
|
||||
it "should have a garden and container" do
|
||||
plot.garden.should == garden
|
||||
plot.container.should == container
|
||||
it "should have a garden" do
|
||||
plot.garden.description.should == "This is a **totally** cool garden"
|
||||
end
|
||||
it "should have a container" do
|
||||
plot.container.description.should == "homemade swamp"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
17
spec/views/containers/edit.html.haml_spec.rb
Normal file
17
spec/views/containers/edit.html.haml_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "containers/edit" do
|
||||
before(:each) do
|
||||
@owner = FactoryBot.create(:admin_member)
|
||||
sign_in @owner
|
||||
controller.stub(:current_user) { @owner }
|
||||
@container = assign(:container, FactoryBot.create(:container))
|
||||
render
|
||||
end
|
||||
|
||||
it "renders the edit container form" do
|
||||
assert_select "form", action: containers_path, method: "post" do
|
||||
assert_select "input#container_description", name: "container[description]"
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/views/containers/new.html.haml_spec.rb
Normal file
17
spec/views/containers/new.html.haml_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "containers/new" do
|
||||
before(:each) do
|
||||
@owner = FactoryBot.create(:admin_member)
|
||||
sign_in @owner
|
||||
controller.stub(:current_user) { @owner }
|
||||
@container = assign(:container, FactoryBot.create(:container))
|
||||
render
|
||||
end
|
||||
|
||||
it "renders new container form" do
|
||||
assert_select "form", action: containers_path, method: "post" do
|
||||
assert_select "input#container_description", name: "container[description]"
|
||||
end
|
||||
end
|
||||
end
|
||||
17
spec/views/containers/show.html.haml_spec.rb
Normal file
17
spec/views/containers/show.html.haml_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe "containers/show" do
|
||||
subject { render }
|
||||
|
||||
let!(:container) { FactoryBot.create(:container, description: "Hot Sauce") }
|
||||
|
||||
before do
|
||||
controller.stub(:current_user) { nil }
|
||||
assign(:container, container)
|
||||
render
|
||||
end
|
||||
|
||||
describe "renders a container with no gardens" do
|
||||
it { is_expected.to have_content "There are no gardens to display." }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user