Commit 20aec05d authored by Martin Markech's avatar Martin Markech
Browse files

add tests for manage albums and manage collections

parent 1977db33
......@@ -17,6 +17,7 @@ group :test do
gem 'pry'
gem 'launchy'
gem 'poltergeist'
gem 'capybara-screenshot'
end
# Database Configuration
......
......@@ -61,6 +61,9 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara-screenshot (1.0.14)
capybara (>= 1.0, < 3)
launchy
carrierwave (0.6.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
......@@ -280,6 +283,7 @@ PLATFORMS
DEPENDENCIES
activerecord-jdbcpostgresql-adapter
activerecord-jdbcsqlite3-adapter
capybara-screenshot
coffee-rails
launchy
pg
......
require "spec_helper"
module Refinery
module PhotoGallery
module Admin
describe AlbumsController, type: :controller do
refinery_login_with_devise [:refinery, :superuser]
before do
logged_in_user.plugins = logged_in_user.plugins | %w(refinerycms_photo_gallery)
end
describe "#index" do
it "succeeds" do
get :index
expect(response).to be_success
expect(response).to render_template(:index)
end
end
=begin
describe "#index" do
let!(:album) { FactoryGirl.create(:album) }
it "succeeds" do
get :index
img_path = "#{Rails.root.join("tmp/capybara")}/screenshot2.png"
page.save_screenshot(img_path)
Launchy.open img_path
expect(response).to be_success
expect(response).to render_template(:index)
end
end
=end
end
end
end
end
FactoryGirl.define do
factory :collection, class: Refinery::PhotoGallery::Collection do
title { Faker::Lorem::word }
description "collection description"
end
end
\ No newline at end of file
FactoryGirl.define do
factory :authentication_devise_user, :class => Refinery::Authentication::Devise::User do
sequence(:username) { |n| "refinery#{n}" }
sequence(:email) { |n| "refinery#{n}@example.com" }
password "refinerycms"
password_confirmation "refinerycms"
end
factory :authentication_devise_refinery_user, :parent => :authentication_devise_user do
roles { [ ::Refinery::Authentication::Devise::Role[:refinery] ] }
after(:create) do |user|
::Refinery::Plugins.registered.each_with_index do |plugin, index|
user.plugins.create(:name => plugin.name, :position => index)
end
end
end
factory :authentication_devise_refinery_superuser, :parent => :authentication_devise_refinery_user do
roles {
[
::Refinery::Authentication::Devise::Role[:refinery],
::Refinery::Authentication::Devise::Role[:superuser]
]
}
end
end
\ No newline at end of file
require "spec_helper"
describe "manage album items", :type => :feature do
refinery_login_with_devise :authentication_devise_refinery_superuser
context "when no album items" do
it "invites to create one" do
#save_and_open_page
visit refinery.photo_gallery_admin_albums_path
expect(page).to have_content("There are no albums yet. Click \"Create new album\" to add your first album.")
end
end
describe "submenu links" do
it "should have submenu links" do
visit refinery.photo_gallery_admin_albums_path
within "#actions" do
expect(page).to have_content("Collections")
expect(page).to have_content("Manage")
end
end
end
describe "action links" do
it "shows create new album" do
visit refinery.photo_gallery_admin_albums_path
within "#actions" do
expect(page).to have_content("Create new album")
expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/photo-gallery/albums/new']")
end
end
it "shows create new collection" do
visit refinery.photo_gallery_admin_albums_path
within "#actions" do
expect(page).to have_content("Create new collection")
expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/photo-gallery/collections/new']")
end
end
end
describe "new/create" do
it "allows to create albums" do
visit refinery.photo_gallery_admin_albums_path
click_link "Create new album"
fill_in "Title", :with => "My first album"
fill_in "Path prefix", :with => "16_04"
fill_in "Description", :with => "This is long story description ... "
click_button "Save"
expect(page).to have_content("'My first album' was successfully added.")
expect(Refinery::PhotoGallery::Album.count).to eq(1)
end
end
describe "edit/update" do
before { FactoryGirl.create(:album, :title => "Update me") }
it "updates album" do
visit refinery.photo_gallery_admin_albums_path
expect(page).to have_content("Update me")
click_link "Edit this album"
fill_in "Title", :with => "Updated"
click_button "Save"
expect(page).to have_content("'Updated' was successfully updated.")
end
end
describe "destroy" do
before { FactoryGirl.create(:album, :title => "Delete me") }
it "removes album" do
visit refinery.photo_gallery_admin_albums_path
click_link "Remove this album forever"
expect(page).to have_content("'Delete me' was successfully removed.")
expect(Refinery::PhotoGallery::Album.count).to eq(0)
end
end
end
\ No newline at end of file
require "spec_helper"
describe "manage collection items", :type => :feature do
refinery_login_with_devise :authentication_devise_refinery_superuser
context "when no collection items" do
it "invites to create one" do
#save_and_open_page
visit refinery.photo_gallery_admin_collections_path
expect(page).to have_content("There are no collections yet. Click \"Create new collection\" to add your first collection.")
end
end
describe "new/create" do
it "allows to create collections" do
visit refinery.photo_gallery_admin_collections_path
click_link "Create new collection"
fill_in "Title", :with => "My first collection"
fill_in "Description", :with => "My collection description ..."
click_button "Save"
expect(page).to have_content("'My first collection' was successfully added.")
expect(Refinery::PhotoGallery::Collection.count).to eq(1)
end
end
describe "edit/update" do
before { FactoryGirl.create(:collection, :title => "Update me") }
it "updates collection" do
visit refinery.photo_gallery_admin_collections_path
expect(page).to have_content("Update me")
click_link "Edit this collection"
fill_in "Title", :with => "Updated"
click_button "Save"
expect(page).to have_content("'Updated' was successfully updated.")
end
end
describe "destroy" do
before { FactoryGirl.create(:collection, :title => "Delete me") }
it "removes collection" do
visit refinery.photo_gallery_admin_collections_path
click_link "Remove this collection forever"
expect(page).to have_content("'Delete me' was successfully removed.")
expect(Refinery::PhotoGallery::Collection.count).to eq(0)
end
end
end
\ No newline at end of file
......@@ -7,6 +7,9 @@ require File.expand_path("../dummy/config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
Capybara::Screenshot.autosave_on_failure = false
Rails.backtrace_cleaner.remove_silencers!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment