Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7451cd5
comment out unused specs
drusepth May 21, 2021
5e0e85d
remove cucumber
drusepth May 21, 2021
1d380db
remove better_errors
drusepth May 21, 2021
79ba60f
remove capybara
drusepth May 21, 2021
9de0e46
remove factorybot
drusepth May 21, 2021
9c75029
remove guard
drusepth May 21, 2021
a1dc586
clean slate tests
drusepth May 21, 2021
434f3f0
clean config files
drusepth May 21, 2021
2361578
remove linker tests
drusepth May 21, 2021
699b9a8
comment out more tests
drusepth May 21, 2021
6fe86c5
Add test command to readme
drusepth May 21, 2021
f13e791
remove linker fixtures
drusepth May 21, 2021
a8c4e96
remove more fixtures
drusepth May 21, 2021
30ee8a6
rebuild test db
drusepth May 21, 2021
77ab502
just... comment them all out
drusepth May 21, 2021
2af5748
first passing test
drusepth May 21, 2021
960ea5b
move commented out tests
drusepth May 22, 2021
b45f71f
don't compile js in test env
drusepth May 22, 2021
120a763
i guess we probably should compile js in test env but i dunno how, so…
drusepth May 22, 2021
27a623c
eod
drusepth May 22, 2021
d920543
add smoke tests for MainController
drusepth May 22, 2021
0e4b466
remove skylight config
drusepth May 22, 2021
f0a05b4
move tests to another dir temporarily
drusepth May 22, 2021
f876451
add some tests for user/universe/pages
drusepth May 24, 2021
a5e2432
Merge branch 'master' into travis-2021
drusepth May 24, 2021
903de11
Merge branch 'master' into travis-2021
drusepth May 24, 2021
a544daf
Merge branch 'travis-2021' of github.com:indentlabs/notebook into tra…
drusepth May 24, 2021
fb647aa
revise tests action
drusepth May 24, 2021
7fda9bd
add ruby 3 to tests matrix
drusepth May 24, 2021
fcb2ba3
remove perf test
drusepth May 24, 2021
6d362b5
manually compile js in action step
drusepth May 24, 2021
76fb623
remove ruby3 from tests
drusepth May 24, 2021
72ad2e4
try assets:precompile instead
drusepth May 24, 2021
1d3cecd
set up node manually
drusepth May 24, 2021
16e0f3e
update node
drusepth May 24, 2021
194e14f
check out setup{} format
drusepth May 24, 2021
c7de9ff
remove travis
drusepth May 24, 2021
8630d7d
Merge branch 'master' into travis-2021
drusepth May 27, 2021
c400df3
recompile gemfile
drusepth May 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add some tests for user/universe/pages
  • Loading branch information
drusepth committed May 24, 2021
commit f8764519f4a94d8f12abd6249ba6bd0c34f831e2
1 change: 1 addition & 0 deletions app/models/billing/billing_plan.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class BillingPlan < ApplicationRecord
FREE_IDS = [1]
PREMIUM_IDS = [2, 3, 4, 5, 6]
end
1 change: 1 addition & 0 deletions app/models/page_types/universe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Universe < ApplicationRecord
has_many :lores

has_many :contributors, dependent: :destroy
has_many :contributing_users, through: :contributors, source: :user

has_many :documents
has_many :timelines
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
starter:
id: 1
name: Starter User
email: test@test.test
selected_billing_plan_id: 1

premium:
id: 2
name: Premium User
email: test@test.test
selected_billing_plan_id: 3
26 changes: 26 additions & 0 deletions test/models/content_page_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'test_helper'

class ContentPageTest < ActiveSupport::TestCase
test "Content pages require a user to create" do
Rails.application.config.content_types[:all].each do |page_type|
assert_raises(ActiveRecord::RecordInvalid) do
page_type.create!
end
end
end

test "Content page privacy levels" do
user = User.first
Rails.application.config.content_types[:all].each do |page_type|
page = page_type.new(user: user, privacy: 'private')

assert user.can_read?(page)
assert_not User.new.can_read?(page)
# TODO collaborators

assert user.can_update?(page)
assert_not User.new.can_update?(page)
# TODO collaborators
end
end
end
46 changes: 46 additions & 0 deletions test/models/universe_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'test_helper'

class UniverseTest < ActiveSupport::TestCase
test "Universe contributors can view/modify pages when private" do
owner = User.first
contributor = User.last
assert_not_equal(owner.id, contributor.id, "Test problem: Owner and contributor need different ideas!")

universe = Universe.create!(name: "Test Universe", user: owner)
universe.contributing_users << contributor
assert universe.contributing_users.include?(contributor), "Contributor is a contributor"

Rails.application.config.content_types[:all_non_universe].each do |page_type|
page = page_type.new(user: owner, universe_id: universe.id, privacy: 'private')

assert contributor.can_read?(page), "Contributor can view shared #{page_type.name}"
assert contributor.can_update?(page), "Contributor can edit shared #{page_type.name}"

assert owner.can_delete?(page), "Owner can delete their own shared #{page_type.name}"
assert_not contributor.can_delete?(page), "Contributors cannot delete shared #{page_type.name}"
end
end

test "Universe Premium is shared" do
owner = User.first
owner.selected_billing_plan_id = BillingPlan::PREMIUM_IDS.first
contributor = User.last
contributor.selected_billing_plan_id = BillingPlan::FREE_IDS.first
assert_not_equal(owner.id, contributor.id, "Test problem: Owner and contributor need different ideas!")

Rails.application.config.content_types[:premium].each do |page_type|
assert owner.can_create?(page_type), "Owner can create #{page_type.name}"
assert_not contributor.can_create?(page_type), "Contributor cannot create #{page_type.name}"
end

universe = Universe.create!(name: "Test Universe", user: owner)
universe.contributing_users << contributor

Rails.application.config.content_types[:all_non_universe].each do |page_type|
page = page_type.new(universe_id: universe.id, user: contributor)

assert page.creatable_by?(owner), "Owner can create #{page_type}"
# assert page.creatable_by?(contributor), "Contributor can create #{page_type}"
end
end
end
45 changes: 45 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
test "User can create billing plan -specific pages" do
free_user = User.new
free_user.selected_billing_plan_id = 1

premium_user = User.new
premium_user.selected_billing_plan_id = BillingPlan::PREMIUM_IDS.first

Rails.application.config.content_types[:free].each do |page_type|
assert free_user.can_create?(page_type), "free user CAN create #{page_type.name}"
assert premium_user.can_create?(page_type), "premium user CAN create #{page_type.name}"
end

Rails.application.config.content_types[:premium].each do |page_type|
assert_not free_user.can_create?(page_type), "free user CANNOT create #{page_type.name}"
assert premium_user.can_create?(page_type), "premium user CAN create #{page_type.name}"
end
end

test "User can view their own content regardless of plan" do
user = User.new
Rails.application.config.content_types[:all].each do |page_type|
page = page_type.new(user: user)
assert user.can_read?(page)
end
end

test "User can edit their own content regardless of plan" do
user = User.new
Rails.application.config.content_types[:all].each do |page_type|
page = page_type.new(user: user)
assert user.can_update?(page)
end
end

test "User can delete their own content" do
user = User.new
Rails.application.config.content_types[:all].each do |page_type|
page = page_type.new(user: user)
assert user.can_delete?(page)
end
end
end