Skip to content

Commit

Permalink
Test management of projects and collaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Sep 4, 2014
1 parent 32ebfe7 commit 36abecb
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 12 deletions.
12 changes: 6 additions & 6 deletions app/views/projects/_file_buttons.html.haml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
.btn-group
- if can? :edit, project
= link_to(edit_project_path(@episode, project), :title=>'Edit this project?', :class=> "btn btn-default") do
= link_to(edit_project_path(@episode, project), :title=>'Edit this project?', :class=> "btn btn-default", id: "project#{project.to_param}-edit-link") do
%i.fa.fa-pencil
- if project.may_advance?
- case project.aasm_state
- when "project"
=link_to(advance_project_path(@episode, project), :method => :post,:title=>'Finish this project', :class=> "btn btn-default") do
=link_to(advance_project_path(@episode, project), :method => :post,:title=>'Finish this project', :class=> "btn btn-default", id: "project#{project.to_param}-advance-link") do
%i.fa.fa-check
- when "record"
=link_to(advance_project_path(@episode, project), :method => :post,:title=>'Revive this project', :class=> "btn btn-default") do
=link_to(advance_project_path(@episode, project), :method => :post,:title=>'Revive this project', :class=> "btn btn-default", id: "project#{project.to_param}-advance-link") do
%i.fa.fa-bolt
- if project.may_recess?
- case project.aasm_state
- when "idea"
=link_to(recess_project_path(@episode, project), :method => :post,:title=>'Archive this project', :class=> "btn btn-default") do
=link_to(recess_project_path(@episode, project), :method => :post,:title=>'Archive this project', :class=> "btn btn-default", id: "project#{project.to_param}-recess-link") do
%i.fa.fa-archive
- when "invention"
=link_to(recess_project_path(@episode, project), :method => :post,:title=>"Restart this project", :class=> "btn btn-default") do
=link_to(recess_project_path(@episode, project), :method => :post,:title=>"Restart this project", :class=> "btn btn-default", id: "project#{project.to_param}-recess-link") do
%i.fa.fa-lightbulb-o
-if can? :destroy, project
= link_to(project_path(@episode, project), :title=>'Delete this project?', :class=> "btn btn-default", :method => :delete, data: { confirm: "Are you sure you want to delete this project? This can't be undone!" }) do
= link_to(project_path(@episode, project), :title=>'Delete this project?', :class=> "btn btn-default", id: "project#{project.to_param}-delete-link", :method => :delete, data: { confirm: "Are you sure you want to delete this project? This can't be undone!" }) do
%i.fa.fa-trash-o
4 changes: 2 additions & 2 deletions app/views/projects/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
- if @project.users.empty?
No
Hackers:
.well.well-sm
.well.well-sm#hackers
- @project.users.each do |user|
= link_to(user_path(user.id)) do
= image_tag user.gravatar_url(:size => "64"), alt: user.name, title: user.name, class: "img-thumbnail"
= image_tag user.gravatar_url(:size => "64"), alt: user.name, title: user.name, class: "img-thumbnail", id: "user#{user.id}-gravatar"
- unless @project.aasm_state == "invention"
%p.pull-right
- if @project.users.empty? or !@project.users.include? current_user
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
end
factory :project, class: Project do
aasm_state 'project'
after(:create) { |project| project.users << create(:user) }
end
factory :invention, class: Project do
aasm_state 'invention'
after(:create) { |project| project.users << create(:user) }
end
factory :record, class: Project do
aasm_state 'record'
Expand Down
48 changes: 45 additions & 3 deletions spec/features/collaboration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
require 'rails_helper'

feature "Collaboration" do
scenario "User creates a new project" do
project = create(:idea)
scenario "User joins a project" do
user = create(:user)
project = create(:idea)
sign_in user

visit "/projects/#{project.to_param}"

click_link "Join this project"
expect {
click_link "Join this project"
}.to change(Project.populated, :count).by(1)
expect(page).to have_css("#user#{user.id}-gravatar")
expect(page).to have_text("Welcome to the project #{user.name}!")
end

scenario "User leaves a project" do
user = create(:user)
project = create(:project, users: [user])
sign_in user

visit "/projects/#{project.to_param}"
click_link "Leave this project"

expect(page).not_to have_css("#user#{user.id}-gravatar")
end

scenario "User likes a project" do
user = create(:user)
project = create(:idea)
sign_in user

visit "/projects/#{project.to_param}"

expect {
click_link "like-#{project.to_param}"
}.to change(Project.liked, :count).by(1)
expect(page).not_to have_css("like-#{project.to_param}")
end

scenario "User dislikes a project" do
user = create(:user)
project = create(:idea)
sign_in user

visit "/projects/#{project.to_param}"
click_link "like-#{project.to_param}"

expect {
click_link "dislike-#{project.to_param}"
}.to change(Project.liked, :count).by(-1)
expect(page).not_to have_css("dislike-#{project.to_param}")
end

end
73 changes: 72 additions & 1 deletion spec/features/project_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,79 @@

fill_in "project_title", :with => title
fill_in "project_description", :with => description
click_button "Create Project"

expect {
click_button "Create Project"
}.to change(Project, :count).by(1)
expect(page).to have_text("an idea by #{user.name}")
expect(page).to have_text(title)
expect(page).to have_text(description)
end

scenario "User edits a project" do
user = create(:user)
project = create(:idea, originator: user )
sign_in user
title = Faker::Lorem.sentence
description = Faker::Lorem.paragraph

visit "/projects/#{project.to_param}/edit"

fill_in "project_title", :with => title
fill_in "project_description", :with => description
click_button "Update Project"

expect(page).to have_text("an idea by #{user.name}")
expect(page).to have_text(title)
expect(page).to have_text(description)
end

scenario "User deletes a project" do
user = create(:user)
project = create(:idea, originator: user )
sign_in user

visit "/projects/#{project.to_param}"

expect {
click_link "project#{project.to_param}-delete-link"
}.to change(Project, :count).by(-1)
end

scenario "User archives an idea" do
user = create(:user)
project = create(:idea, originator: user )
sign_in user

visit "/projects/#{project.to_param}"

expect {
click_link "project#{project.to_param}-recess-link"
}.to change(Project.archived, :count).by(1)
end

scenario "User finishes a project" do
user = create(:user)
project = create(:project, originator: user, users: [user] )
sign_in user

visit "/projects/#{project.to_param}"

expect {
click_link "project#{project.to_param}-advance-link"
}.to change(Project.finished, :count).by(1)
end

scenario "User restarts a project" do
user = create(:user)
project = create(:invention, originator: user, users: [user] )

sign_in user
visit "/projects/#{project.to_param}"
click_link "project#{project.to_param}-recess-link"

project.reload
expect(project.aasm_state).to eq('project')
end

end

0 comments on commit 36abecb

Please sign in to comment.