Skip to content

Business intelligence made simple

Test permissions

Andrew Kane6bd6441eddc4
diff --git a/test/internal/app/controllers/application_controller.rb b/test/internal/app/controllers/application_controller.rb
index 09705d12..75cf2087 100644
--- a/test/internal/app/controllers/application_controller.rb
+++ b/test/internal/app/controllers/application_controller.rb
@@ -1,2 +1,5 @@
class ApplicationController < ActionController::Base
+ def current_user
+ User.last
+ end
end
diff --git a/test/internal/app/models/user.rb b/test/internal/app/models/user.rb
new file mode 100644
index 00000000..4a57cf07
--- /dev/null
+++ b/test/internal/app/models/user.rb
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
diff --git a/test/internal/db/schema.rb b/test/internal/db/schema.rb
index 6d6b4303..b8355bfe 100644
--- a/test/internal/db/schema.rb
+++ b/test/internal/db/schema.rb
@@ -49,4 +49,8 @@ ActiveRecord::Schema.define do
t.text :description
t.timestamps null: false
end
+
+ create_table :users do |t|
+ t.string :name
+ end
end
diff --git a/test/permissions_test.rb b/test/permissions_test.rb
new file mode 100644
index 00000000..0d663bae
--- /dev/null
+++ b/test/permissions_test.rb
@@ -0,0 +1,30 @@
+require_relative "test_helper"
+
+class PermissionsTest < ActionDispatch::IntegrationTest
+ def setup
+ Blazer::Query.delete_all
+ User.delete_all
+ end
+
+ def test_list
+ with_new_user do |user|
+ create_query(name: "# Test", creator: user)
+ get blazer.root_path
+ assert_response :success
+ assert_match "# Test", response.body
+ end
+
+ with_new_user do
+ get blazer.root_path
+ assert_response :success
+ refute_match "# Test", response.body
+ end
+ end
+
+ private
+
+ def with_new_user
+ user = User.create!
+ yield user
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index fe78e408..f662c503 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -23,8 +23,8 @@ class ActionDispatch::IntegrationTest
assert_response :success
end
- def create_query(statement: "SELECT 1")
- Blazer::Query.create!(statement: statement, data_source: "main", status: "active")
+ def create_query(statement: "SELECT 1", **attributes)
+ Blazer::Query.create!(statement: statement, data_source: "main", status: "active", **attributes)
end
def create_check(**attributes)