Skip to content

Commit d63b459

Browse files
committed
add back test system and add tests for Diary.creatable_by?
1 parent 4da5b4e commit d63b459

File tree

8 files changed

+158
-1
lines changed

8 files changed

+158
-1
lines changed

Gemfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ gem "sass-rails", "~>5.0", require: assets
4545
gem "rails-sass-images", require: assets
4646
gem "uglifier", require: assets
4747

48+
group :development, :test do
49+
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
50+
gem "byebug", platforms: :mri
51+
end
52+
4853
group :development do
4954
gem "annotate"
5055
gem "better_errors"
5156
gem "binding_of_caller"
52-
gem "byebug", platform: :mri
5357
gem "capistrano", "~>2.15", github: 'capistrano', branch: 'legacy-v2'
5458
gem "capistrano-maintenance"
5559
gem "letter_opener"
@@ -62,6 +66,12 @@ group :development do
6266
gem "web-console"
6367
end
6468

69+
group :test do
70+
# Adds support for Capybara system testing and selenium driver
71+
gem "capybara", ">= 2.15"
72+
gem "selenium-webdriver"
73+
end
74+
6575
group :production, :alpha do
6676
gem "unicorn", "~>5.1"
6777
gem "gctools", "~>0.2"

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ services:
1313
- ./app:/linuxfr.org/app
1414
- ./db:/linuxfr.org/db
1515
- ./public:/linuxfr.org/public
16+
- ./test:/linuxfr.org/test
1617
# uploads are shared with the nginx service
1718
- data-uploads:/linuxfr.org/uploads
1819
tmpfs:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "test_helper"
2+
3+
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
4+
driven_by :selenium, using: :headless_firefox, screen_size: [1400, 1400]
5+
end

test/fixtures/accounts.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Required Anonyme login for Account model
2+
anonymous:
3+
user: community
4+
login: Anonyme
5+
6+
role: inactive
7+
8+
<% 1000.times do |n| %>
9+
visitor_<%= n%>:
10+
user: <%= "visitor_#{n}" %>
11+
login: <%= "visitor_#{n}" %>
12+
email: <%= "visitor_#{n}@example.com" %>
13+
role: visitor
14+
<% end %>
15+
16+
visitor_negative_karma:
17+
user: visitor_negative_karma
18+
login: visitor_negative_karma
19+
20+
role: visitor
21+
karma: -100
22+
23+
visitor_zero_karma:
24+
user: visitor_zero_karma
25+
login: visitor_zero_karma
26+
27+
role: visitor
28+
karma: 0
29+
30+
<% 7.times do |n| %>
31+
editor_<%= n%>:
32+
user: <%= "editor_#{n}" %>
33+
login: <%= "editor_#{n}" %>
34+
email: <%= "editor_#{n}@example.com" %>
35+
role: editor
36+
<% end %>
37+
38+
<% 2.times do |n| %>
39+
maintainer_<%= n%>:
40+
user: <%= "maintainer_#{n}" %>
41+
login: <%= "maintainer_#{n}" %>
42+
email: <%= "maintainer_#{n}@example.com" %>
43+
role: maintainer
44+
<% end %>
45+
46+
<% 12.times do |n| %>
47+
moderator_<%= n%>:
48+
user: <%= "moderator_#{n}" %>
49+
login: <%= "moderator_#{n}" %>
50+
email: <%= "moderator_#{n}@example.com" %>
51+
role: moderator
52+
<% end %>
53+
54+
<% 6.times do |n| %>
55+
admin_<%= n%>:
56+
user: <%= "admin_#{n}" %>
57+
login: <%= "admin_#{n}" %>
58+
email: <%= "admin_#{n}@example.com" %>
59+
role: admin
60+
<% end %>

test/fixtures/diaries.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
lorem:
2+
title: Lorem ipsum
3+
cached_slug: lorem-ipsum
4+
owner: visitor_1
5+
body: Lorem ipsum
6+
wiki_body: Lorem ipsum

test/fixtures/users.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Required Collectif user for User model
2+
community:
3+
name: Collectif
4+
cached_slug: collectif
5+
6+
<% 1000.times do |n| %>
7+
visitor_<%= n%>:
8+
name: <%= "visitor_#{n}" %>
9+
cached_slug: <%= "visitor_#{n}" %>
10+
<% end %>
11+
12+
visitor_negative_karma:
13+
name: visitor_negative_karma
14+
cached_slug: visitor_negative_karma
15+
16+
visitor_zero_karma:
17+
name: visitor_zero_karma
18+
cached_slug: visitor_zero_karma
19+
20+
<% 7.times do |n| %>
21+
editor_<%= n%>:
22+
name: <%= "editor_#{n}" %>
23+
cached_slug: <%= "editor_#{n}" %>
24+
<% end %>
25+
26+
<% 2.times do |n| %>
27+
maintainer_<%= n%>:
28+
name: <%= "maintainer_#{n}" %>
29+
cached_slug: <%= "maintainer_#{n}" %>
30+
<% end %>
31+
32+
<% 12.times do |n| %>
33+
moderator_<%= n%>:
34+
name: <%= "moderator_#{n}" %>
35+
cached_slug: <%= "moderator_#{n}" %>
36+
<% end %>
37+
38+
<% 6.times do |n| %>
39+
admin_<%= n%>:
40+
name: <%= "admin_#{n}" %>
41+
cached_slug: <%= "admin_#{n}" %>
42+
<% end %>

test/models/diary_test.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'test_helper'
2+
3+
class DiaryTest < ActiveSupport::TestCase
4+
test "user with positive karma can create diary" do
5+
diary = diaries(:lorem).dup;
6+
assert diary.creatable_by?(diary.owner.account);
7+
assert diary.save();
8+
end
9+
10+
test "user with zero karma cannot create diary" do
11+
diary = diaries(:lorem).dup;
12+
diary.owner = users(:visitor_zero_karma);
13+
assert_not diary.creatable_by?(diary.owner.account);
14+
assert diary.save(), "Diary model were not saved";
15+
end
16+
17+
test "user with negative karma cannot create diary" do
18+
diary = diaries(:lorem).dup;
19+
diary.owner = users(:visitor_negative_karma);
20+
assert_not diary.creatable_by?(diary.owner.account);
21+
assert diary.save(), "Diary model were not saved";
22+
end
23+
end

test/test_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ENV['RAILS_ENV'] ||= 'test'
2+
require_relative '../config/environment'
3+
require 'rails/test_help'
4+
5+
class ActiveSupport::TestCase
6+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7+
fixtures :all
8+
9+
# Add more helper methods to be used by all tests here...
10+
end

0 commit comments

Comments
 (0)