By default tables are public

1.0
Fernando Blat 14 years ago
parent 425e05c95e
commit 266abc1f98

@ -8,6 +8,10 @@ class Table < Sequel::Model(:user_tables)
## Callbacks
def before_validation
self.privacy ||= PUBLIC
end
# Before creating a user table a table should be created in the database.
# This table has an empty schema
def before_create
@ -32,7 +36,11 @@ class Table < Sequel::Model(:user_tables)
## End of Callbacks
def private?
privacy.nil? || privacy == PRIVATE
privacy == PRIVATE
end
def public?
!private?
end
def toggle_privacy!

@ -34,7 +34,7 @@ feature "Tables JSON API" do
Capybara.current_driver = :rack_test
user = create_user
table = create_table :user_id => user.id
table = create_table :user_id => user.id, :privacy => Table::PRIVATE
table.should be_private

@ -4,9 +4,9 @@ require 'spec_helper'
describe Table do
it "should have a privacy associated and it should be private by default" do
table = Table.new
table.privacy.should be_nil
table.should be_private
table = create_table
table.privacy.should_not be_nil
table.should_not be_private
end
it "should be associated to a database table" do
@ -67,7 +67,7 @@ describe Table do
it "has a toggle_privacy! method to toggle the table privacy" do
user = create_user
table = create_table :user_id => user.id
table = create_table :user_id => user.id, :privacy => Table::PRIVATE
table.should be_private
table.toggle_privacy!

@ -3,7 +3,10 @@ module CartoDB
def new_table(attributes = {})
attributes = attributes.dup
attributes[:name] ||= String.random(10)
attributes[:user_id] ||= rand(1000)
if attributes[:user_id].nil?
user = create_user
attributes[:user_id] = user.id
end
Table.new(attributes)
end

Loading…
Cancel
Save