Merge pull request #62 from indentlabs/feature/migrate-tests

Migrate tests to rspec and cucumber
This commit is contained in:
Andrew Brown 2016-10-03 14:13:05 +02:00 committed by GitHub
commit d0f33cbbb0
85 changed files with 1146 additions and 1163 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ set_aws_credentials.sh
# Ignore map images uploaded to Locations
/locations
public/sitemap.xml.gz
profiles

2
.rspec Normal file
View File

@ -0,0 +1,2 @@
--color
--require spec_helper

View File

@ -1 +1 @@
2.2.3
2.3.1

35
Gemfile
View File

@ -1,6 +1,6 @@
source 'https://rubygems.org'
gem 'rails'
gem 'rails', '4.2.5'
# Storage
gem 'aws-sdk', '~> 1.50'
@ -10,12 +10,12 @@ gem 'paperclip', '~> 4.2.0'
gem 'rmagick', '2.13.4'
# Authentication
gem 'devise'
gem 'bcrypt'
gem 'devise'
# Design
gem 'sass-rails'
gem 'material_icons'
gem 'sass-rails'
# Quality of Life
gem 'cocoon'
@ -42,11 +42,8 @@ gem 'chartkick'
gem 'slack-notifier'
group :production do
# gem 'less-rails'
# gem 'less-rails-fontawesome'
gem 'uglifier', '>= 1.3.0'
# gem 'bootplus-rails'
gem 'rails_12factor'
gem 'uglifier', '>= 1.3.0'
end
group :test, :production do
@ -54,25 +51,27 @@ group :test, :production do
gem 'therubyracer', platforms: :ruby
end
group :test, :development do
group :test do
gem 'better_errors'
gem 'binding_of_caller'
gem 'capybara'
gem 'selenium-webdriver'
gem 'codeclimate-test-reporter', require: false
gem 'coveralls', require: false
gem 'simplecov', require: false
gem 'rubocop', require: false
gem 'cucumber-rails', require: false
gem 'database_cleaner'
gem 'sqlite3'
gem 'tzinfo-data' # addresses a bug when working on Windows
gem 'factory_girl_rails'
gem 'guard'
gem 'guard-minitest'
gem 'guard-rubocop'
gem 'pry'
gem 'better_errors'
gem 'binding_of_caller'
gem 'selenium-webdriver'
gem 'simplecov', require: false
gem 'sqlite3'
gem 'tzinfo-data' # addresses a bug when working on Windows
gem 'rails-perftest'
gem 'ruby-prof'
gem 'rspec-prof'
gem 'rspec-rails'
gem 'rubocop', require: false
gem 'ruby-prof', '0.15.9'
gem 'shoulda-matchers', '~> 3.1'
end

View File

@ -7,36 +7,36 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
actionmailer (4.2.5)
actionpack (= 4.2.5)
actionview (= 4.2.5)
activejob (= 4.2.5)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.0)
actionview (= 4.2.0)
activesupport (= 4.2.0)
rack (~> 1.6.0)
actionpack (4.2.5)
actionview (= 4.2.5)
activesupport (= 4.2.5)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0)
activesupport (= 4.2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.5)
activesupport (= 4.2.5)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0)
activesupport (= 4.2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.5)
activesupport (= 4.2.5)
globalid (>= 0.3.0)
activemodel (4.2.0)
activesupport (= 4.2.0)
activemodel (4.2.5)
activesupport (= 4.2.5)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
activerecord (4.2.5)
activemodel (= 4.2.5)
activesupport (= 4.2.5)
arel (~> 6.0)
activesupport (4.2.0)
activesupport (4.2.5)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
@ -44,7 +44,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.4.0)
arel (6.0.3)
ast (2.2.0)
ast (2.3.0)
aws-sdk (1.66.0)
aws-sdk-v1 (= 1.66.0)
aws-sdk-v1 (1.66.0)
@ -58,7 +58,7 @@ GEM
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
capybara (2.6.2)
capybara (2.9.2)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
@ -73,20 +73,23 @@ GEM
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
cocoon (1.2.9)
codeclimate-test-reporter (0.6.0)
simplecov (>= 0.7.1, < 1.0.0)
coderay (1.1.1)
coffee-rails (4.0.1)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
railties (>= 4.0.0, < 5.2.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
coveralls (0.8.13)
json (~> 1.8)
simplecov (~> 0.11.0)
concurrent-ruby (1.0.2)
coveralls (0.8.15)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
tins (>= 1.6.0, < 2)
cucumber (2.4.0)
builder (>= 2.1.2)
cucumber-core (~> 1.5.0)
@ -97,41 +100,40 @@ GEM
multi_test (>= 0.1.2)
cucumber-core (1.5.0)
gherkin (~> 4.0)
cucumber-rails (1.4.3)
cucumber-rails (1.4.5)
capybara (>= 1.1.2, < 3)
cucumber (>= 1.3.8, < 3)
cucumber (>= 1.3.8, < 4)
mime-types (>= 1.16, < 4)
nokogiri (~> 1.5)
railties (>= 3, < 5)
railties (>= 3, < 5.1)
cucumber-wire (0.0.1)
database_cleaner (1.5.3)
dateslices (0.0.4)
rails (> 4)
debug_inspector (0.0.2)
devise (3.5.6)
devise (4.2.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
railties (>= 4.1.0, < 5.1)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
execjs (2.6.0)
execjs (2.7.0)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
railties (>= 3.0.0)
ffi (1.9.10)
ffi (1.9.14)
formatador (0.2.5)
gherkin (4.0.0)
globalid (0.3.6)
globalid (0.3.7)
activesupport (>= 4.1.0)
guard (2.13.0)
guard (2.14.0)
formatador (>= 0.2.4)
listen (>= 2.7, <= 4.0)
listen (>= 2.7, < 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
@ -139,25 +141,25 @@ GEM
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-minitest (2.4.4)
guard-minitest (2.4.6)
guard-compat (~> 1.2)
minitest (>= 3.0)
guard-rubocop (1.2.0)
guard (~> 2.0)
rubocop (~> 0.20)
hike (1.2.3)
i18n (0.7.0)
jquery-rails (4.1.1)
jquery-rails (4.2.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
libv8 (3.16.14.13)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
libv8 (3.16.14.15)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.0.3)
nokogiri (>= 1.5.9)
lumberjack (1.0.10)
@ -165,22 +167,23 @@ GEM
mime-types (>= 1.16, < 4)
material_icons (2.2.0)
railties (>= 3.2)
medium-editor-rails (2.2.0)
medium-editor-rails (2.3.1)
railties (>= 3.0)
meta-tags (2.2.0)
actionpack (>= 3.2.0)
meta-tags (2.3.1)
actionpack (>= 3.2.0, <= 5.1.0)
method_source (0.8.2)
mime-types (3.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.8.4)
multi_json (1.11.2)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.9.1)
multi_json (1.12.1)
multi_test (0.1.2)
nenv (0.3.0)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
notiffany (0.0.8)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
@ -189,27 +192,28 @@ GEM
activesupport (>= 3.2.0)
cocaine (~> 0.5.5)
mime-types
parser (2.3.0.7)
parser (2.3.1.4)
ast (~> 2.2)
pg (0.18.4)
pg (0.19.0)
pkg-config (1.1.7)
powerpack (0.1.1)
pry (0.10.3)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
activemodel (= 4.2.0)
activerecord (= 4.2.0)
activesupport (= 4.2.0)
rails (4.2.5)
actionmailer (= 4.2.5)
actionpack (= 4.2.5)
actionview (= 4.2.5)
activejob (= 4.2.5)
activemodel (= 4.2.5)
activerecord (= 4.2.5)
activesupport (= 4.2.5)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0)
railties (= 4.2.5)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
@ -225,75 +229,101 @@ GEM
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.4)
rails_stdout_logging (0.0.4)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (4.2.5)
actionpack (= 4.2.5)
activesupport (= 4.2.5)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.1.2)
rake (11.3.0)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
ref (2.0.0)
responders (2.1.2)
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
rmagick (2.13.4)
rubocop (0.39.0)
parser (>= 2.3.0.7, < 3.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-prof (0.0.7)
rspec (~> 3.0)
ruby-prof
rspec-rails (3.5.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rubocop (0.43.0)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-prof (0.15.9)
ruby-progressbar (1.7.5)
ruby-progressbar (1.8.1)
ruby_dep (1.4.0)
rubyzip (1.2.0)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
sass (~> 3.2.2)
sprockets (~> 2.8, < 3.0)
sprockets-rails (~> 2.0)
selenium-webdriver (2.53.0)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
selenium-webdriver (2.53.4)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
shellany (0.0.1)
simplecov (0.11.2)
shoulda-matchers (3.1.1)
activesupport (>= 4.0.0)
simplecov (0.12.0)
docile (~> 1.1.0)
json (~> 1.8)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slack-notifier (1.5.1)
slop (3.6.0)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.3.3)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sprockets (3.7.0)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.11)
term-ansicolor (1.3.2)
term-ansicolor (1.4.0)
tins (~> 1.0)
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
tins (1.6.0)
tilt (2.0.5)
tins (1.12.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2016.3)
tzinfo-data (1.2016.7)
tzinfo (>= 1.0.0)
uglifier (3.0.0)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.0.3)
unicode-display_width (1.1.1)
warden (1.2.6)
rack (>= 1.0)
websocket (1.2.3)
@ -311,6 +341,7 @@ DEPENDENCIES
capybara
chartkick
cocoon
codeclimate-test-reporter
coffee-rails
coveralls
cucumber-rails
@ -329,16 +360,19 @@ DEPENDENCIES
paperclip (~> 4.2.0)
pg
pry
rails
rails (= 4.2.5)
rails-jquery-autocomplete
rails-perftest
rails_12factor
rmagick (= 2.13.4)
rspec-prof
rspec-rails
rubocop
ruby-prof
ruby-prof (= 0.15.9)
sass-rails
selenium-webdriver
serendipitous!
shoulda-matchers (~> 3.1)
simplecov
slack-notifier
sqlite3
@ -347,4 +381,4 @@ DEPENDENCIES
uglifier (>= 1.3.0)
BUNDLED WITH
1.13.1
1.13.2

View File

@ -1,6 +1,7 @@
= notebook
{<img src="https://travis-ci.org/indentlabs/notebook.png?branch=master" alt="Build Status" />}[https://travis-ci.org/indentlabs/notebook]
{<img src="https://coveralls.io/repos/indentlabs/notebook/badge.svg?branch=master" alt="Coverage Status" />}[https://coveralls.io/r/indentlabs/notebook?branch=master]
{<img src="https://codeclimate.com/github/indentlabs/notebook/badges/gpa.svg" />}[https://codeclimate.com/github/indentlabs/notebook]
{<img src="https://codeclimate.com/github/indentlabs/notebook/badges/coverage.svg" />}[https://codeclimate.com/github/indentlabs/notebook/coverage]
{<img src="http://inch-ci.org/github/indentlabs/notebook.svg?branch=master" alt="Inline docs" />}[http://inch-ci.org/github/indentlabs/notebook]
== What is notebook?
@ -40,13 +41,13 @@ Install curl
Install rvm
\curl -sSL https://get.rvm.io | bash
source ~/.rvm/scripts/rvm
Install ruby 2.1.2
rvm install ruby 2.1.2
rvm use 2.1.2
Install rails 4.0.1
@ -76,8 +77,8 @@ Optional: To enable the uploading and editing of images (used in Locations manag
And then set your AWS credentials with
source set_aws_credentials.rb
Finally, run the server with
Finally, run the server with
rails server

View File

@ -16,9 +16,21 @@ class ApplicationController < ActionController::Base
before_action do
if current_user && session[:universe_id]
@universe_scope = Universe.find_by(user: current_user, id: session[:universe_id])
else
@universe_scope = nil
end
end
before_action do
@page_title ||= ''
@page_keywords ||= %w[writing author nanowrimo novel character fiction fantasy universe creative dnd roleplay larp game design]
@page_description ||= 'Notebook is a set of tools for writers, game designers, and roleplayers to create magnificent universes — and everything within them.'
end
before_action do
@question ||= ''
end
def content_type_from_controller(content_controller_name)
content_controller_name.to_s.chomp('Controller').singularize.constantize
end

View File

@ -1,25 +1,19 @@
<% if question && question[:field] && question[:question].present? %>
<%
if question.present? &&
question[:field].present? &&
question[:question].present? &&
content.present?
%>
<div class="content-question card-panel hoverable light-blue lighten-4">
<i class="material-icons <%= content.class.color %>-text circle right"><%= content.class.icon %></i>
<%= question[:question] %>
<%= form_for content do |f| %>
<%
value = content.send(question[:field])
if value.is_a?(ActiveRecord::Associations::CollectionProxy)
klass = value.first.class || value.build.class
%>
<%# render 'content/form/relation_input', f: f, attribute: question[:field].chomp('ship').pluralize, relation: question[:field].chomp('ships').pluralize %>
<%
else
%>
<div class="input-field">
<%= f.text_field question[:field], class: 'content-question-input' %>
<%= f.label content.class.human_attribute_name(question[:field]) %>
</div>
<%
end
%>
<div class="input-field">
<%= f.text_field question[:field], class: 'content-question-input' %>
<%= f.label content.class.human_attribute_name(question[:field]) %>
</div>
<%# Using a plain old form.submit creates a button that only responds to a click on the button text,
not anywhere else on the button. %>

View File

@ -37,5 +37,5 @@ Rails.application.configure do
config.active_record.raise_in_transactional_callbacks = true
default_url_options[:host] = 'localhost:3000'
default_url_options[:host] = 'test.host'
end

16
features/accounts.feature Normal file
View File

@ -0,0 +1,16 @@
Feature: User accounts
Scenario: I sign up
When I sign up
Then I should see my dashboard
Scenario: I log in as an existing user
Given I have an account
When I log in
Then I should see my dashboard
Scenario: I log out, and then log in
When I sign up
Then I log out
Then I log in
Then I should see my dashboard

31
features/content.feature Normal file
View File

@ -0,0 +1,31 @@
Feature: Character sheets
As an author,
I want to record information about the content I create
So that I don't forget
Background:
Given I have an account
And I log in
Scenario Outline: I create new content
When I create a <content_type>
Then that <content_type> should be saved
Examples:
| content_type |
| character |
| location |
| item |
| universe |
Scenario Outline: I change my content's name
Given I have created a <content_type>
When I change my <content_type>'s name
Then that new name should be saved
Examples:
| content_type |
| character |
| location |
| item |
| universe |

View File

@ -0,0 +1,8 @@
Feature: Serendipitous cards
Scenario: I update character info using a serendipitous card
Given I am logged-in
And I create a character
When I view that character
And I answer the Serendipitous question
Then that new field should be saved

View File

@ -0,0 +1,82 @@
When 'I sign up' do
@user = build(:user)
visit new_user_registration_path
fill_in 'user_name', with: 'User Name'
fill_in 'user_email', with: @user.email
fill_in 'user_password', with: 'password'
fill_in 'user_password_confirmation', with: 'password'
click_button 'Sign up'
@user = User.where(email: @user.email).first
end
Given 'I have an account' do
step('I sign up')
end
When 'I log in' do
step('I log out')
visit new_user_session_path
fill_in 'user_email', with: @user.email
fill_in 'user_password', with: 'password'
click_button 'Log in'
end
Given 'I am logged-in' do
step('I sign up')
end
When 'I log out' do
visit destroy_user_session_path
end
Then 'I should see my dashboard' do
expect(current_path).to eq(dashboard_path)
end
When(/^I create a (character|location|item|universe)$/) do |model|
visit new_polymorphic_path(model)
fill_in "#{model}_name", with: 'My new content'
click_on "Create #{model.titlecase}"
@model = model.classify.constantize.where(name: 'My new content', user: @user).first
end
Then(/^that (character|location|item|universe) should be saved$/) do |model|
expect(@user.send(model.pluralize).length).to eq(1)
end
Given(/^I have created a (character|location|item|universe)$/) do |model|
@model = create(model.to_sym, user: @user)
end
When(/^I change my (character|location|item|universe)\'s name$/) do |model|
visit polymorphic_path(@model)
click_on "Edit this #{model}"
fill_in "#{model}_name", with: 'My changed name'
click_on "Update #{model.titlecase}"
@model.reload
end
When(/^I view that (character|location|item|universe)$/) do |_model|
visit polymorphic_path(@model)
end
Then(/^that new name should be saved$/) do
expect(@model.name).to eq('My changed name')
end
When 'I answer the Serendipitous question' do
@modified_field_name = find(:css, '.content-question-input')[:id].split('_', 2)[1]
@model[@modified_field_name] = 'Previous Value'
@model.save
@previous_field_value = @model[@modified_field_name]
find(:css, '.content-question-input').set('Content Question Answer')
find('.content-question-submit').click
end
Then 'that new field should be saved' do
@model.reload
expect(@model[@modified_field_name]).to eq('Content Question Answer')
end

View File

@ -0,0 +1 @@
World(FactoryGirl::Syntax::Methods)

View File

@ -1,17 +0,0 @@
Feature: User account creation
As user of the site
I want to sign up to the website
So that, at a later date, I can access the content that I previously created
@wip
Scenario: A new user saves some content
When I sign up
And I create some content
And I log out
And I log in
Then I should see the content that I created
@wip
Scenario: A user signs up and gets a confirmation email
When I sign up
Then I should get an email

View File

@ -0,0 +1,29 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe AdminController, type: :controller do
describe 'GET #dashboard' do
before { get :dashboard }
it { is_expected.to respond_with(200) }
end
describe 'GET #universes' do
before { get :universes }
it { is_expected.to respond_with(200) }
end
describe 'GET #characters' do
before { get :characters }
it { is_expected.to respond_with(200) }
end
describe 'GET #locations' do
before { get :locations }
it { is_expected.to respond_with(200) }
end
describe 'GET #items' do
before { get :items }
it { is_expected.to respond_with(200) }
end
end

View File

@ -0,0 +1,7 @@
require 'rails_helper'
require 'support/devise'
require 'support/content_controller_example'
RSpec.describe CharactersController, type: :controller do
it_behaves_like 'a controller for a content item'
end

View File

@ -0,0 +1,182 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe CharactersGeneratorController, type: :controller do
describe 'GET #age' do
before { get :age }
it { is_expected.to respond_with(200) }
describe 'assigns(:lower_limit)' do
subject { assigns(:lower_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be <= assigns(:upper_limit) }
end
describe 'assigns(:upper_limit)' do
subject { assigns(:upper_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= assigns(:lower_limit) }
end
end
describe 'GET #bodytype' do
before { get :bodytype }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_types)' do
subject { assigns(:possible_types) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #eyecolor' do
before { get :eyecolor }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_colors)' do
subject { assigns(:possible_colors) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #facialhair' do
before { get :facialhair }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_types)' do
subject { assigns(:possible_styles) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #haircolor' do
before { get :haircolor }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_colors)' do
subject { assigns(:possible_colors) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #hairstyle' do
before { get :hairstyle }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_styles)' do
subject { assigns(:possible_styles) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #height' do
before { get :height }
it { is_expected.to respond_with(200) }
describe 'assigns(:lower_foot_limit)' do
subject { assigns(:lower_foot_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= 0 }
it { is_expected.to be <= assigns(:upper_foot_limit) }
end
describe 'assigns(:upper_foot_limit)' do
subject { assigns(:upper_foot_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= 0 }
it { is_expected.to be >= assigns(:lower_foot_limit) }
end
describe 'assigns(:lower_inch_limit)' do
subject { assigns(:lower_inch_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= 0 }
it { is_expected.to be <= assigns(:upper_inch_limit) }
end
describe 'assigns(:upper_inch_limit)' do
subject { assigns(:upper_inch_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= 0 }
it { is_expected.to be >= assigns(:lower_inch_limit) }
end
end
describe 'GET #identifyingmark' do
before { get :identifyingmark }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_marks)' do
subject { assigns(:possible_marks) }
it { is_expected.to_not be_nil }
end
describe 'assigns(:possible_locations)' do
subject { assigns(:possible_locations) }
it { is_expected.to_not be_nil }
end
end
describe 'GET #name' do
before { get :name }
it { is_expected.to respond_with(200) }
describe 'assigns(:male_first_names)' do
subject { assigns(:male_first_names) }
it { is_expected.to_not be_empty }
end
describe 'assigns(:female_first_names)' do
subject { assigns(:female_first_names) }
it { is_expected.to_not be_empty }
end
describe 'assigns(:last_names)' do
subject { assigns(:last_names) }
it { is_expected.to_not be_empty }
end
describe 'assigns(:all_first_names)' do
subject { assigns(:all_first_names) }
it { is_expected.to_not be_empty }
end
describe 'assigns(:all_last_names)' do
subject { assigns(:all_last_names) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #race' do
before { get :race }
it { is_expected.to respond_with(200) }
describe 'assigns(:possible_races)' do
subject { assigns(:possible_races) }
it { is_expected.to_not be_empty }
end
end
describe 'GET #skintone' do
before { get :bodytype }
it { is_expected.to respond_with(200) }
end
describe 'GET #weight' do
before { get :weight }
it { is_expected.to respond_with(200) }
describe 'assigns(:lower_limit)' do
subject { assigns(:lower_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be > 0 }
it { is_expected.to be <= assigns(:upper_limit) }
end
describe 'assigns(:upper_limit)' do
subject { assigns(:upper_limit) }
it { is_expected.to be_an(Integer) }
it { is_expected.to be >= assigns(:lower_limit) }
end
end
end

View File

@ -0,0 +1,48 @@
require 'rails_helper'
require 'support/generated_lists_example'
RSpec.describe EquipmentGeneratorController, type: :controller do
it_behaves_like 'a generator', :shield_types do
before { get :armor_shield }
end
it_behaves_like 'a generator', :weapon_types do
before { get :weapon }
end
it_behaves_like 'a generator', :axe_types do
before { get :weapon_axe }
end
it_behaves_like 'a generator', :bow_types do
before { get :weapon_bow }
end
it_behaves_like 'a generator', :club_types do
before { get :weapon_club }
end
it_behaves_like 'a generator', :fist_weapon_types do
before { get :weapon_fist }
end
it_behaves_like 'a generator', :flexible_types do
before { get :weapon_flexible }
end
it_behaves_like 'a generator', :thrown_types do
before { get :weapon_thrown }
end
it_behaves_like 'a generator', :polearm_types do
before { get :weapon_polearm }
end
it_behaves_like 'a generator', :shortsword_types do
before { get :weapon_shortsword }
end
it_behaves_like 'a generator', :sword_types do
before { get :weapon_sword }
end
end

View File

@ -0,0 +1,7 @@
require 'rails_helper'
require 'support/devise'
require 'support/content_controller_example'
RSpec.describe ItemsController, type: :controller do
it_behaves_like 'a controller for a content item'
end

View File

@ -0,0 +1,7 @@
require 'rails_helper'
require 'support/devise'
require 'support/content_controller_example'
RSpec.describe LocationsController, type: :controller do
it_behaves_like 'a controller for a content item'
end

View File

@ -0,0 +1,55 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe LocationsGeneratorController, type: :controller do
describe 'GET #name' do
before { get :name }
it { is_expected.to respond_with(200) }
describe 'assigns(:root_name)' do
subject { assigns(:root_name) }
it { is_expected.to_not be_blank }
end
describe 'assigns(:prefix_occurrence)' do
subject { assigns(:prefix_occurrence) }
it { is_expected.to_not be_blank }
it { is_expected.to be_between(0, 1).inclusive }
end
describe 'assigns(:postfix_occurrence)' do
subject { assigns(:postfix_occurrence) }
it { is_expected.to_not be_blank }
it { is_expected.to be_between(0, 1).inclusive }
end
describe 'assigns(:syllables_upper_limit)' do
subject { assigns(:syllables_upper_limit) }
it { is_expected.to_not be_blank }
it { is_expected.to be >= assigns(:syllables_lower_limit) }
end
describe 'assigns(:syllables_lower_limit)' do
subject { assigns(:syllables_lower_limit) }
it { is_expected.to_not be_blank }
it { is_expected.to be >= 0 }
it { is_expected.to be <= assigns(:syllables_upper_limit) }
end
describe 'assigns(:prefixes)' do
subject { assigns(:prefixes) }
it { is_expected.to_not be_blank }
end
describe 'assigns(:postfixes)' do
subject { assigns(:postfixes) }
it { is_expected.to_not be_blank }
end
describe 'assigns(:syllables)' do
subject { assigns(:syllables) }
it { is_expected.to_not be_blank }
end
end
end

View File

@ -0,0 +1,9 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe MainController, type: :controller do
describe 'GET #index' do
before { get :index }
it { is_expected.to respond_with(200) }
end
end

View File

@ -0,0 +1,7 @@
require 'rails_helper'
require 'support/devise'
require 'support/content_controller_example'
RSpec.describe UniversesController, type: :controller do
it_behaves_like 'a controller for a content item'
end

View File

@ -0,0 +1,14 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe UsersController, type: :controller do
let(:user) { create(:user) }
describe 'GET #show/:id' do
it 'responds successfully with an HTTP 200 status code' do
get :show, id: user.id
expect(response).to be_success
expect(response).to have_http_status(200)
end
end
end

View File

@ -0,0 +1,17 @@
require 'rails_helper'
require 'support/devise'
RSpec.describe WriteController, type: :controller do
describe 'GET #editor, scene_id: 1' do
before do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
sign_in @user
get :editor, scene_id: 1
end
it { is_expected.to respond_with(200) }
end
end

View File

@ -1,8 +1,10 @@
FactoryGirl.define do
sequence :email do |n|
"email#{n}@example.com"
end
factory :user do
sequence :email do |n|
"user#{n}@example.com"
end
email
password 'password'
end

View File

@ -0,0 +1,9 @@
require 'rails_helper'
require 'support/privacy_example'
require 'support/public_scope_example'
RSpec.describe Character, type: :model do
it_behaves_like 'content with privacy'
it_behaves_like 'content with an is_public scope'
it { is_expected.to validate_presence_of(:name) }
end

9
spec/models/item_spec.rb Normal file
View File

@ -0,0 +1,9 @@
require 'rails_helper'
require 'support/privacy_example'
require 'support/public_scope_example'
RSpec.describe Item, type: :model do
it_behaves_like 'content with privacy'
it_behaves_like 'content with an is_public scope'
it { is_expected.to validate_presence_of(:name) }
end

View File

@ -0,0 +1,9 @@
require 'rails_helper'
require 'support/privacy_example'
require 'support/public_scope_example'
RSpec.describe Location, type: :model do
it_behaves_like 'content with privacy'
it_behaves_like 'content with an is_public scope'
it { is_expected.to validate_presence_of(:name) }
end

View File

@ -0,0 +1,8 @@
require 'rails_helper'
require 'support/privacy_example'
require 'support/public_scope_example'
RSpec.describe Universe, type: :model do
it_behaves_like 'content with privacy'
it { is_expected.to validate_presence_of(:name) }
end

12
spec/models/user_spec.rb Normal file
View File

@ -0,0 +1,12 @@
require 'rails_helper'
RSpec.describe User, type: :model do
context "when user's email is profile.image.test@example.com" do
let(:user) { build(:user, email: 'profile.image.test@example.com') }
describe '.image_url' do
subject { user.image_url }
it { is_expected.to match('https://www.gravatar.com/avatar/d2fd00e79c471f49c33b6bcb6b08d08d') }
end
end
end

66
spec/rails_helper.rb Normal file
View File

@ -0,0 +1,66 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migration and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
# config.use_transactional_fixtures = true
# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, :type => :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!
# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.include FactoryGirl::Syntax::Methods
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

111
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,111 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# The `.rspec` file also contains a few flags that are not defaults but that
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start
RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
# defined using `chain`, e.g.:
# be_bigger_than(2).and_smaller_than(4).description
# # => "be bigger than 2 and smaller than 4"
# ...rather than:
# # => "be bigger than 2"
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended, and will default to
# `true` in RSpec 4.
mocks.verify_partial_doubles = true
end
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
# have no way to turn it off -- the option exists only for backwards
# compatibility in RSpec 3). It causes shared context metadata to be
# inherited by the metadata hash of host groups and examples, rather than
# triggering implicit auto-inclusion in groups with matching metadata.
config.shared_context_metadata_behavior = :apply_to_host_groups
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # This allows you to limit a spec run to individual examples or groups
# # you care about by tagging them with `:focus` metadata. When nothing
# # is tagged with `:focus`, all examples get run. RSpec also provides
# # aliases for `it`, `describe`, and `context` that include `:focus`
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
# config.filter_run_when_matching :focus
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
# # you configure your source control system to ignore this file.
# config.example_status_persistence_file_path = "spec/examples.txt"
#
# # Limits the available syntax to the non-monkey patched syntax that is
# # recommended. For more details, see:
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
# config.disable_monkey_patching!
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = 'doc'
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end

View File

@ -0,0 +1,70 @@
require 'rails_helper'
require 'support/devise'
include Rails.application.routes.url_helpers
shared_examples_for 'a controller for a content item' do
before(:all) do
@model_class = described_class.controller_name.classify.constantize
@model_name = described_class.controller_name.classify.constantize.model_name.param_key
end
before(:each) do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
sign_in @user
end
let(:model) { create(@model_name.to_sym, user: @user) }
describe 'GET #index' do
before { get :index }
it { is_expected.to respond_with(200) }
it { is_expected.to render_template('content/index') }
describe 'assigns(:content)' do
subject { assigns(:content) }
it { is_expected.to_not be_nil }
end
end
describe 'GET #new' do
before { get :new }
it { is_expected.to respond_with(200) }
it { is_expected.to render_template("#{@model_name.pluralize}/new") }
end
describe 'POST #create' do
before do
post :create, @model_name => {
name: model.name
}
end
it { is_expected.to redirect_to(polymorphic_path(assigns(:content))) }
end
describe 'GET #edit' do
before { get :edit, id: model.id }
it { is_expected.to respond_with(200) }
it { is_expected.to render_template("#{@model_name.pluralize}/edit") }
end
describe 'PUT #update' do
before do
put :update, id: model.id, @model_name => {
name: model.name
}
end
it { is_expected.to redirect_to(polymorphic_path(model)) }
end
describe 'DELETE #destroy' do
before { delete :destroy, id: model.id }
it { is_expected.to redirect_to(polymorphic_path(@model_class)) }
describe 'the destroyed model' do
subject { @model_class.find_by_id(model.id) }
it { is_expected.to be_nil }
end
end
end

5
spec/support/devise.rb Normal file
View File

@ -0,0 +1,5 @@
require 'devise'
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
end

View File

@ -0,0 +1,9 @@
require 'rails_helper'
shared_examples_for 'a generator' do |types|
it { is_expected.to respond_with(200) }
it "assigns #{types}" do
expect(assigns(types)).to_not be_empty
end
end

View File

@ -0,0 +1,17 @@
require 'rails_helper'
shared_examples_for 'content with privacy' do
context 'model is public' do
let(:model) do
build(
described_class.model_name.param_key.to_sym,
privacy: 'public'
)
end
describe '.public_content?' do
subject { model.public_content? }
it { is_expected.to be true }
end
end
end

View File

@ -0,0 +1,71 @@
require 'rails_helper'
shared_examples_for 'content with an is_public scope' do
context 'when model is in a public universe' do
let(:universe) { create(:universe, privacy: 'public') }
context 'when model is private' do
let(:model) do
create(
described_class.model_name.param_key.to_sym,
universe: universe,
privacy: 'private'
)
end
describe '#is_public' do
subject { described_class.is_public }
it { is_expected.to include(model) }
end
end
context 'when model is public' do
let(:model) do
create(
described_class.model_name.param_key.to_sym,
universe: universe,
privacy: 'public'
)
end
describe '#is_public' do
subject { described_class.is_public }
it { is_expected.to include(model) }
end
end
end
context 'when model is in a private universe' do
let(:universe) { build(:universe, privacy: 'private') }
context 'when model is private' do
let(:model) do
create(
described_class.model_name.param_key.to_sym,
universe: universe,
privacy: 'private'
)
end
describe '#is_public' do
subject { described_class.is_public }
it { is_expected.to_not include(model) }
end
end
context 'when model is public' do
let(:model) do
create(
described_class.model_name.param_key.to_sym,
universe: universe,
privacy: 'public'
)
end
describe '#is_public' do
subject { described_class.is_public }
it { is_expected.to include(model) }
end
end
end
end

View File

@ -0,0 +1,34 @@
describe 'app/views/cards/serendipitous/_content_question.html.erb' do
let(:question) { 'What is my name?' }
let(:field) { :name }
let(:question_object) { { field: field, question: question } }
let(:content) { create(:character) }
shared_examples_for 'an empty serendipitous card' do
it 'renders nothing' do
render partial: 'cards/serendipitous/content_question', locals: { question: question_object, content: content }
expect(response).to match(/decided not to render serendipitous card/)
end
end
context 'when question is an empty string' do
let(:question_object) { '' }
it_behaves_like 'an empty serendipitous card'
end
context 'when question[:field] is an empty string' do
let(:question_object) { { field: '', question: question } }
it_behaves_like 'an empty serendipitous card'
end
context 'when question[:question] is an empty string' do
let(:question_object) { { field: field, question: '' } }
it_behaves_like 'an empty serendipitous card'
end
context 'when content is an empty string' do
let(:content) { '' }
it_behaves_like 'an empty serendipitous card'
end
end

View File

View File

@ -1,29 +0,0 @@
require 'test_helper'
class AdminControllerTest < ActionController::TestCase
test "should get dashboard" do
get :dashboard
assert_response :success
end
test "should get universes" do
get :universes
assert_response :success
end
test "should get characters" do
get :characters
assert_response :success
end
test "should get locations" do
get :locations
assert_response :success
end
test "should get items" do
get :items
assert_response :success
end
end

View File

@ -1,5 +0,0 @@
require 'test_helper'
# Tests for the ApplicationController
class ApplicationControllerTest < ActionController::TestCase
end

View File

@ -1,76 +0,0 @@
require 'test_helper'
# Tests for the CharactersController class
class CharactersControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
@universe = create(:universe, user: @user)
sign_in @user
end
test 'should get index' do
get :index
assert_response :success
assert_not_nil assigns(:content)
end
test 'should get new' do
get :new
assert_response :success
end
test 'should create character' do
character = build(:character, universe: @universe, age: 70)
assert_difference('Character.count') do
post :create, character: {
age: character.age,
name: character.name,
universe: character.universe
}
end
assert_redirected_to character_path(assigns(:content))
end
test 'should show character' do
character = create(:character, user: @user)
get :show, id: character.id
assert_response :success
end
test 'should get edit' do
character = create(:character, user: @user)
get :edit, id: character.id
assert_response :success
end
test 'should update character' do
character = create(:character, age: 70, universe: @universe, user: @user)
put :update, id: character.id, character: {
age: character.age,
name: character.name,
universe: character.universe
}
assert_response 302
assert_redirected_to character_path(character)
end
test 'should destroy character' do
character = create(:character, user: @user)
assert_difference('Character.count', -1) do
delete :destroy, id: character.id
end
assert_redirected_to characters_url
end
end

View File

@ -1,71 +0,0 @@
require 'test_helper'
# Tests for the CharactersGeneratorController
class CharactersGeneratorControllerTest < ActionController::TestCase
test 'age' do
assert_assigns :age, [:upper_limit, :lower_limit]
assert_operator assigns(:lower_limit), :<=, assigns(:upper_limit)
end
test 'body type' do
assert_assigns :bodytype, [:possible_types]
end
test 'eye color' do
assert_assigns :eyecolor, [:possible_colors]
end
test 'facial hair' do
assert_assigns :facialhair, [:possible_styles]
end
test 'hair color' do
assert_assigns :haircolor, [:possible_colors]
end
test 'hair style' do
assert_assigns :hairstyle, [:possible_styles]
end
test 'height' do
assert_assigns :height, [
:lower_foot_limit,
:upper_foot_limit,
:lower_inch_limit,
:upper_inch_limit
]
assert_operator assigns(:lower_foot_limit), :<=, assigns(:upper_foot_limit)
assert_operator assigns(:lower_inch_limit), :<=, assigns(:upper_inch_limit)
assert_operator assigns(:lower_foot_limit), :>=, 0
assert_operator assigns(:lower_inch_limit), :>=, 0
end
test 'identifying mark' do
assert_assigns :identifyingmark, [:possible_marks, :possible_locations]
end
test 'name' do
assert_assigns :name, [
:male_first_names,
:female_first_names,
:last_names,
:all_first_names,
:all_last_names
]
end
test 'race' do
assert_assigns :race, [:possible_races]
end
test 'skin tone' do
assert_assigns :skintone, [:possible_tones]
end
test 'weight' do
assert_assigns :weight, [:upper_limit, :lower_limit]
assert_operator assigns(:lower_limit), :<=, assigns(:upper_limit)
assert_operator assigns(:lower_limit), :>=, 0
end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class ContentControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,48 +0,0 @@
require 'test_helper'
# Tests for the EquipmentGeneratorController
class EquipmentGeneratorControllerTest < ActionController::TestCase
test 'armor shield' do
assert_assigns :armor_shield, [:shield_types]
end
test 'weapon' do
assert_assigns :weapon, [:weapon_types]
end
test 'weapon axe' do
assert_assigns :weapon_axe, [:axe_types]
end
test 'weapon bow' do
assert_assigns :weapon_bow, [:bow_types]
end
test 'weapon club' do
assert_assigns :weapon_club, [:club_types]
end
test 'weapon fist' do
assert_assigns :weapon_fist, [:fist_weapon_types]
end
test 'weapon flexible' do
assert_assigns :weapon_flexible, [:flexible_types]
end
test 'weapon thrown' do
assert_assigns :weapon_thrown, [:thrown_types]
end
test 'weapon polearm' do
assert_assigns :weapon_polearm, [:polearm_types]
end
test 'weapon shortsword' do
assert_assigns :weapon_shortsword, [:shortsword_types]
end
test 'weapon sword' do
assert_assigns :weapon_sword, [:sword_types]
end
end

View File

@ -1,91 +0,0 @@
require 'test_helper'
# Tests for the LocationsController class
class LocationsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
@universe = create(:universe, user: @user)
sign_in @user
end
test 'should get index' do
get :index
assert_response :success
assert_not_nil assigns(:content)
end
test 'should get new' do
get :new
assert_response :success
end
test 'should create location' do
location = build(:location, user: @user)
assert_difference('Location.count') do
post :create, location: {
name: location.name,
universe: @universe,
user: @user
}
end
assert_redirected_to location_path(assigns(:content))
end
test 'should show location' do
location = create(:location, user: @user)
get :show, id: location
assert_response :success
end
test 'should get edit' do
location = create(:location, user: @user)
get :edit, id: location.id
assert_response :success
end
test 'should update location' do
location = create(:location, user: @user)
put :update, id: location, location: {
name: location.name + ' Updated',
universe: @universe
}
assert_response 302
assert_redirected_to location_path(location)
end
test 'should destroy location' do
location = create(:location, user: @user)
assert_difference('Location.count', -1) do
delete :destroy, id: location.id
end
assert_redirected_to locations_url
end
test 'should create location with image' do
location = build(:location)
assert_difference('Location.count') do
map = fixture_file_upload('mordor_map.jpg', 'image/jpeg')
post :create, location: {
name: location.name,
map: map,
universe: @universe,
user: @user
}
end
assert_redirected_to location_path(assigns(:content))
end
end

View File

@ -1,29 +0,0 @@
require 'test_helper'
# Tests for the LocationsGeneratorController
class LocationsGeneratorControllerTest < ActionController::TestCase
test 'name' do
assert_assigns :name, [
:root_name,
:prefix_occurrence,
:postfix_occurrence,
:syllables_upper_limit,
:syllables_lower_limit,
:prefixes,
:postfixes,
:syllables
]
assert_operator assigns(:prefix_occurrence), :<=, 1
assert_operator assigns(:prefix_occurrence), :>=, 0
assert_operator assigns(:postfix_occurrence), :<=, 1
assert_operator assigns(:postfix_occurrence), :>=, 0
assert_operator(
assigns(:syllables_lower_limit),
:<=,
assigns(:syllables_upper_limit))
assert_operator assigns(:syllables_lower_limit), :>=, 0
end
end

View File

@ -1,10 +0,0 @@
require 'test_helper'
# Tests for the MainController class, which serves the model-non-specific
# pages of the site, like the front page.
class MainControllerTest < ActionController::TestCase
test 'should get index' do
get :index
assert_response :success
end
end

View File

@ -1,5 +0,0 @@
require 'test_helper'
class SiblingshipControllerTest < ActionController::TestCase
# Nothing to test in the SiblingshipController yet
end

View File

@ -1,67 +0,0 @@
require 'test_helper'
# Tests for the UniversesController
class UniversesControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
sign_in @user
end
test 'should get index' do
get :index
assert_response :success
assert_not_nil assigns(:content)
end
test 'should get new' do
get :new
assert_response :success
end
test 'should create universe' do
universe = build(:universe, user: @user)
assert_difference('Universe.count') do
post :create, universe: { name: universe.name }
end
assert_redirected_to universe_path(assigns(:content))
end
test 'should show universe' do
universe = create(:universe, user: @user)
get :show, id: universe.id
assert_response :success
end
test 'should get edit' do
universe = create(:universe, user: @user)
get :edit, id: universe.id
assert_response :success
end
test 'should update universe' do
universe = create(:universe, user: @user)
put :update, id: universe.id, universe: { name: universe.name + ' Updated' }
assert_response 302
assert_redirected_to universe_path(universe)
end
test 'should destroy universe' do # MWAHAHAHAHAHA!!!!!!!
universe = create(:universe, user: @user)
assert_difference('Universe.count', -1) do
delete :destroy, id: universe.id
end
assert_redirected_to universes_url
end
end

View File

@ -1,11 +0,0 @@
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
test "should get user profile without error" do
test_user = User.create(email: 'test+test@test.test', password: 'testtesttest')
get :show, id: test_user.id
assert_response :success
end
end

View File

@ -1,16 +0,0 @@
require 'test_helper'
class WriteControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
sign_in @user
end
test 'should get editor' do
get :editor, scene_id: 1
assert_response :success
end
end

View File

@ -1,11 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
character_id: 1
location_id: 1
user_id: 1
two:
character_id: 1
location_id: 1
user_id: 1

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 KiB

View File

@ -1,13 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
character_id: 1
item_id: 1
user_id: 1
favorite: false
two:
character_id: 1
item_id: 1
user_id: 1
favorite: false

Binary file not shown.

Before

Width:  |  Height:  |  Size: 355 KiB

View File

@ -1,47 +0,0 @@
require 'active_support/concern'
module HasPrivacyTest
extend ActiveSupport::Concern
included do
test 'responds to public_content' do
assert_respond_to(@object, :public_content?)
end
test 'responds to private_content' do
assert_respond_to(@object, :private_content?)
end
test 'object is public when privacy field contains "public"' do
@object.universe.privacy = 'private'
@object.privacy = 'public'
assert @object.public_content?
refute @object.private_content?
end
test 'object is private when privacy field contains "private"' do
@object.universe.privacy = 'private'
@object.privacy = 'private'
assert @object.private_content?
refute @object.public_content?
end
test 'object is private when privacy field is empty' do
@object.universe.privacy = 'private'
@object.privacy = ''
assert @object.private_content?
refute @object.public_content?
end
test 'object is public when universe is public' do
@object.universe.privacy = 'public'
@object.privacy = 'private'
assert @object.public_content?
refute @object.private_content?
end
end
end

View File

View File

@ -1,6 +0,0 @@
require 'test_helper'
# Tests for the ApplicationHelper class
class ApplicationHelperTest < ActionView::TestCase
# Empty, for now
end

View File

View File

@ -1,17 +0,0 @@
require 'test_helper'
# Tests scenarios related to interacting with Characters
class CharacterStoriesTest < ActionDispatch::IntegrationTest
setup do
@user = log_in_as_user
end
test 'a user can create a new character' do
character = build(:character)
visit new_character_path
fill_in 'character_name', with: character.name
click_on 'Create Character'
assert_equal character_path(Character.where(name: character.name).first), current_path
end
end

View File

@ -1,43 +0,0 @@
require 'test_helper'
# Tests scenarios related to interacting with Locations
class LocationStoriesTest < ActionDispatch::IntegrationTest
setup do
@user = log_in_as_user
@location = create(:location, user: @user)
end
test 'location is displayed on locations list' do
visit locations_path
assert page.has_content?(@location.name),
"Page body didn't contain location name: "\
"#{@location.name} not found in \n#{page.body}"
end
test 'location list edit button edits location' do
visit location_path(@location)
click_on 'Edit this location'
assert_equal edit_location_path(@location), current_path
end
test 'location list view button shows location' do
visit locations_path
within(:css, '.collection-item:first') do
click_on @location.name
end
assert_equal location_path(@location), current_path,
"Not on location path for location #{@location.name}: "\
"#{@location.name} not found in \n#{page.body}"
end
test 'a user can create a new location' do
new_location = build(:location)
visit locations_path
click_on 'Create another location'
fill_in 'location_name', with: new_location.name
click_on 'Create Location'
assert_equal location_path(Location.where(name: new_location.name).first),
current_path
end
end

View File

@ -1,27 +0,0 @@
require 'test_helper'
# Tests for the Serendipitous cards on content pages
class SerendipitousCardTest < ActionDispatch::IntegrationTest
test 'changing character info' do
@user = log_in_as_user
@character = create(:character, user: @user)
@character.save
visit character_path(@character)
modified_field_name = find(:css, '.content-question-input')[:id].split('_', 2)[1]
@character[modified_field_name] = 'Previous Value'
@character.save
previous_field_value = @character[modified_field_name]
find(:css, '.content-question-input').set('Content Question Answer')
find('.content-question-submit').click
# We can't use @character.changed? because after the form is submitted,
# the changes were saved.
@character.reload
assert_equal 'Content Question Answer', @character[modified_field_name],
"expected field #{modified_field_name} to change from '#{previous_field_value}' to 'Content Question Answer', but it was '#{@character[modified_field_name]}'"
end
end

View File

@ -1,43 +0,0 @@
require 'test_helper'
# Tests scenarios related to interacting with Universes
class UniverseStoriesTest < ActionDispatch::IntegrationTest
setup do
@user = log_in_as_user
@universe = create(:universe, user: @user)
end
test 'universe is displayed on universes list' do
visit universes_path
assert page.has_content?(@universe.name),
"Page body didn't contain universe name: "\
"#{@universe.name} not found in \n#{page.body}"
end
test 'universe list edit button edits universe' do
visit universe_path(@universe)
click_on 'Edit this universe'
assert_equal edit_universe_path(@universe), current_path
end
test 'universe list view button shows universe' do
visit universes_path
within(:css, '.collection-item:first') do
click_on @universe.name
end
assert_equal universe_path(@universe), current_path,
"Not on universe path for universe #{@universe.name}: "\
"#{@universe.name} not found in \n#{page.body}"
end
test 'a user can create a new universe' do
new_universe = build(:universe)
visit universes_path
click_on 'Create another universe'
fill_in 'universe_name', with: new_universe.name
click_on 'Create Universe'
assert_equal universe_path(Universe.where(name: new_universe.name).first),
current_path
end
end

View File

@ -1,35 +0,0 @@
require 'test_helper'
# Tests scenarios related to users and their accounts
class UserStoriesTest < ActionDispatch::IntegrationTest
test 'clicking sign up goes to the sign up page' do
visit root_url
click_on 'Sign up'
assert_equal new_user_registration_path, current_path
end
test 'submitting the user registration form dumps the user on their dashboard' do
user = build(:user)
register_as user.email, user.password
assert_equal dashboard_path, current_path
end
test 'logging in as an existing user goes to the users dashboard' do
user = create(:user)
log_in_as user.email, user.password
assert_equal dashboard_path, current_path,
'Existing user was not directed to their dashboard \
after logging in'
end
test 'user can register, log out, and log back in' do
user = build(:user)
register_as user.email, user.password
log_out
log_in_as user.email, user.password
assert_equal dashboard_path, current_path
end
end

View File

View File

View File

@ -1,7 +0,0 @@
require 'test_helper'
class ArchenemyshipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class BestFriendshipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class BirthingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,38 +0,0 @@
require 'test_helper'
require 'has_privacy_test'
# Tests for the model class Character
class CharacterTest < ActiveSupport::TestCase
include HasPrivacyTest
setup do
@character = build(:character)
# for HasPrivacyTest
@object = @character
end
test 'character not valid without a name' do
@character.name = nil
refute @character.valid?, 'Character name not being validated for presence'
end
test 'character is_public scope' do
public_universe = create(:universe, privacy: 'public')
private_universe = create(:universe, privacy: 'private')
pub_character_pub_universe = create(:character, privacy: 'public', universe: public_universe)
pub_character_priv_universe = create(:character, privacy: 'public', universe: private_universe)
priv_character_pub_universe = create(:character, privacy: 'private', universe: public_universe)
priv_character_priv_universe = create(:character, privacy: 'private', universe: private_universe)
public_scope = Character.is_public
assert_includes public_scope, pub_character_pub_universe, "didn't contain a public character in a public universe"
assert_includes public_scope, pub_character_priv_universe, "didn't contain a public character in a private universe"
assert_includes public_scope, priv_character_pub_universe, "didn't contain a private character in a public universe"
refute_includes public_scope, priv_character_priv_universe, "contained a private character in a private universe"
end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class FathershipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,36 +0,0 @@
require 'test_helper'
require 'has_privacy_test'
# Tests for the Location model class
class ItemTest < ActiveSupport::TestCase
include HasPrivacyTest
setup do
@item = create(:item)
@object = @item
end
test 'item not valid without a name' do
@item.name = nil
refute @item.valid?, 'Item name is not being validated for presence'
end
test 'item is_public scope' do
public_universe = create(:universe, privacy: 'public')
private_universe = create(:universe, privacy: 'private')
pub_item_pub_universe = create(:item, privacy: 'public', universe: public_universe)
pub_item_priv_universe = create(:item, privacy: 'public', universe: private_universe)
priv_item_pub_universe = create(:item, privacy: 'private', universe: public_universe)
priv_item_priv_universe = create(:item, privacy: 'private', universe: private_universe)
public_scope = Item.is_public
assert_includes public_scope, pub_item_pub_universe, "didn't contain a public item in a public universe"
assert_includes public_scope, pub_item_priv_universe, "didn't contain a public item in a private universe"
assert_includes public_scope, priv_item_pub_universe, "didn't contain a private item in a public universe"
refute_includes public_scope, priv_item_priv_universe, "contained a private item in a private universe"
end
end

View File

@ -1,36 +0,0 @@
require 'test_helper'
require 'has_privacy_test'
# Tests for the Location model class
class LocationTest < ActiveSupport::TestCase
include HasPrivacyTest
setup do
@location = create(:location)
@object = @location
end
test 'location not valid without a name' do
@location.name = nil
refute @location.valid?, 'Location name is not being validated for presence'
end
test 'location is_public scope' do
public_universe = create(:universe, privacy: 'public')
private_universe = create(:universe, privacy: 'private')
pub_location_pub_universe = create(:location, privacy: 'public', universe: public_universe)
pub_location_priv_universe = create(:location, privacy: 'public', universe: private_universe)
priv_location_pub_universe = create(:location, privacy: 'private', universe: public_universe)
priv_location_priv_universe = create(:location, privacy: 'private', universe: private_universe)
public_scope = Location.is_public
assert_includes public_scope, pub_location_pub_universe, "didn't contain a public location in a public universe"
assert_includes public_scope, pub_location_priv_universe, "didn't contain a public location in a private universe"
assert_includes public_scope, priv_location_pub_universe, "didn't contain a private location in a public universe"
refute_includes public_scope, priv_location_priv_universe, "contained a private location in a private universe"
end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class MarriageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class MothershipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class OwnershipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class SiblingshipTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -1,24 +0,0 @@
require 'test_helper'
# Tests for the Universe model class
class UniverseTest < ActiveSupport::TestCase
test 'universe not valid without a name' do
universe = build(:universe, name: nil)
refute universe.valid?, 'Universe name is not being validated for presence'
end
test 'universe is private when privacy field contains "private"' do
universe = build(:universe, privacy: 'private')
assert universe.private_content?
refute universe.public_content?
end
test 'universe is private when privacy field is empty' do
universe = build(:universe, privacy: '')
assert universe.private_content?
refute universe.public_content?
end
end

View File

@ -1,10 +0,0 @@
require 'test_helper'
# Tests for the User model class
class UserTest < ActiveSupport::TestCase
test 'user has a Gravatar profile image' do
user = build(:user, email: 'profile.image.test@example.com')
assert_match 'https://www.gravatar.com/avatar/d2fd00e79c471f49c33b6bcb6b08d08d', user.image_url
end
end

View File

@ -1,9 +0,0 @@
require 'test_helper'
require 'rails/performance_test_help'
# Tests performance by browsing the site
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
class BrowsingTest < ActionDispatch::PerformanceTest
end

View File

@ -1,79 +0,0 @@
require 'simplecov'
require 'coveralls'
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
SimpleCov.start 'rails'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
module ActiveSupport
# Helper methods for unit tests
class TestCase
include FactoryGirl::Syntax::Methods
def log_in_user(user_fixture)
session[:user] = users(user_fixture).id
end
end
end
module ActionController
# Helper methods for controller tests
class TestCase
include Devise::TestHelpers
def assert_assigns(method, assigned = {})
get method
assert_response :success
assigned.each do |val|
assert_not assigns(val).blank?, "#{method} did not assign #{val}"
end
end
end
end
module ActionDispatch
# Helper methods for integration tests
class IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
include FactoryGirl::Syntax::Methods
def register_as(email, password)
visit new_user_registration_path
fill_in 'Email', with: email
fill_in 'Password', with: password
fill_in 'Password confirmation', with: password
within '#new_user' do
click_on 'Sign up'
end
end
def log_in_as(email, password)
visit new_user_session_path
fill_in 'Email', with: email
fill_in 'Password', with: password
within '#new_user' do
click_on 'Log in'
end
end
def log_in_as_user
user = create(:user)
log_in_as user.email, user.password
user
end
def log_out
visit destroy_user_session_path
end
def teardown
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
end