Name of the table is sanitized

1.0
Fernando Blat 14 years ago
parent d1ab9a4581
commit eae52a42f9

@ -28,6 +28,7 @@ class Table < Sequel::Model(:user_tables)
def name=(new_name)
new_name = set_table_name if new_name.blank?
new_name = new_name.sanitize
if !new? && !new_name.blank? && !name.blank? && new_name != name
owner.in_database do |user_database|
user_database.rename_table name, new_name
@ -214,12 +215,12 @@ class Table < Sequel::Model(:user_tables)
end
def set_table_name
base_name = "Untitle table"
base_name = "Untitle table".sanitize
return base_name if user_id.nil?
i = 1
while Table.filter(:user_id => user_id, :name => base_name).count != 0
i += 1
base_name = "Untitle table #{i}"
base_name = "Untitle table #{i}".sanitize
end
base_name
end

@ -63,7 +63,7 @@ class String
return if self.blank?
self.gsub(/<[^>]+>/m,'').normalize.downcase.gsub(/&.+?;/,'-').
gsub(/[^a-z0-9 _-]/,'-').strip.gsub(/\s+/,'-').gsub(/-+/,'-').
gsub(/-/,' ').strip.gsub(/ /,'-')
gsub(/-/,' ').strip.gsub(/ /,'-').gsub(/-/,'_')
end
def strip_tags

@ -65,19 +65,19 @@ feature "Tables JSON API" do
put_json "/api/json/tables/#{table.id}/update", {:name => "My brand new name"}
response.status.should == 200
table.reload
table.name.should == "My brand new name"
table.name.should == "my_brand_new_name"
put_json "/api/json/tables/#{table.id}/update", {:name => ""}
response.status.should == 200
table.reload
table.name.should == "Untitle table"
table.name.should == "untitle_table"
put_json "/api/json/tables/#{old_table.id}/update", {:name => "Untitle table"}
response.status.should == 400
json_response = JSON(response.body)
json_response['errors'].should == ["PGError: ERROR: relation \"Untitle table\" already exists"]
json_response['errors'].should == ["PGError: ERROR: relation \"untitle_table\" already exists"]
old_table.reload
old_table.name.should == "Old table"
old_table.name.should == "old_table"
end
scenario "Update the tags of a table" do
@ -126,12 +126,12 @@ feature "Tables JSON API" do
response.body.should == [
{
"id" => table1.id,
"name" => "My table #1",
"name" => "my_table_1",
"privacy" => "PUBLIC"
},
{
"id" => table2.id,
"name" => "My table #2",
"name" => "my_table_2",
"privacy" => "PRIVATE"
}
].to_json

@ -71,7 +71,7 @@ feature "Dashboard", %q{
page.should have_content("22 tables in your account")
within("ul.your_tables li:eq(1)") do
page.should have_link("Downloaded movies")
page.should have_link("downloaded_movies")
page.should have_content("PRIVATE")
page.should have_content("Last operation 4 minutes ago")
within(:css, "span.tags") do
@ -81,7 +81,7 @@ feature "Dashboard", %q{
end
within("ul.your_tables li:eq(2)") do
page.should have_link("My check-ins")
page.should have_link("my_check_ins")
page.should have_content("PUBLIC")
page.should have_content("Last operation 5 minutes ago")
within(:css, "span.tags") do
@ -92,7 +92,7 @@ feature "Dashboard", %q{
end
within("ul.your_tables li:eq(10).last") do
page.should have_link("Table #8")
page.should have_link("table_8")
page.should have_content("PUBLIC")
page.should have_content("Last operation 6 minutes ago")
within(:css, "span.tags") do
@ -117,7 +117,7 @@ feature "Dashboard", %q{
click_link_or_button('3')
within("ul.your_tables li:eq(1)") do
page.should have_link("Table #19")
page.should have_link("table_19")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("personal")
@ -125,7 +125,7 @@ feature "Dashboard", %q{
end
within("ul.your_tables li:eq(2)") do
page.should have_link("Table #20")
page.should have_link("table_20")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("personal")
@ -143,7 +143,7 @@ feature "Dashboard", %q{
click_link_or_button('Previous')
within("ul.your_tables li:eq(1)") do
page.should have_link("Table #9")
page.should have_link("table_9")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("personal")
@ -151,7 +151,7 @@ feature "Dashboard", %q{
end
within("ul.your_tables li:eq(2)") do
page.should have_link("Table #10")
page.should have_link("table_10")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("personal")
@ -168,9 +168,9 @@ feature "Dashboard", %q{
click_link_or_button('1')
click_link_or_button('Downloaded movies')
click_link_or_button('downloaded_movies')
page.should have_css("h2", :text => 'Downloaded movies')
page.should have_css("h2", :text => 'downloaded_movies')
page.should have_css("p.status", :text => 'PRIVATE')
within(:css, "span.tags") do
page.should have_content("movies")
@ -190,7 +190,7 @@ feature "Dashboard", %q{
page.should have_no_css("ul li a span", :text => "drinking")
within("ul.your_tables li:eq(1)") do
page.should have_link("Favourite restaurants")
page.should have_link("favourite_restaurants")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("restaurants")
@ -208,7 +208,7 @@ feature "Dashboard", %q{
click_link_or_button('Next')
within("ul.your_tables li:eq(1)") do
page.should have_link("Other Table #10")
page.should have_link("other_table_10")
page.should have_content("PUBLIC")
within(:css, "span.tags") do
page.should have_content("vodka")
@ -225,9 +225,9 @@ feature "Dashboard", %q{
click_link_or_button('Previous')
click_link_or_button('Favourite restaurants')
click_link_or_button('favourite_restaurants')
page.should have_css("h2", :text => 'Favourite restaurants')
page.should have_css("h2", :text => 'favourite_restaurants')
page.should have_css("p.status", :text => 'PUBLIC')
within(:css, "span.tags") do
page.should have_content("restaurants")

@ -9,7 +9,7 @@ feature "Tables" do
login_as @user
click_link_or_button("Twitter followers")
click_link_or_button("twitter_followers")
end
scenario "Toggle the privacy of a table" do
@ -29,11 +29,11 @@ feature "Tables" do
end
scenario "Change the name from a table" do
click_link_or_button("Twitter followers")
click_link_or_button("twitter_followers")
page.find("form#change_name input[name='title']").set("New name")
page.find_button('Save').click
page.find("h2").text.should == "New name"
page.find("h2").text.should == "new_name"
end
scenario "Add and remove tags from a table" do

@ -8,7 +8,7 @@ describe Table do
table = Table.new
table.should_not be_valid
table.errors.on(:user_id).should_not be_nil
table.name.should == "Untitle table"
table.name.should == "untitle_table"
end
it "should set a default name different than the previous" do
@ -16,12 +16,12 @@ describe Table do
table = Table.new
table.user_id = user.id
table.save
table.name.should == "Untitle table"
table.name.should == "untitle_table"
table2 = Table.new
table2.user_id = user.id
table2.save.reload
table2.name.should == "Untitle table 2"
table2.name.should == "untitle_table_2"
end
it "should have a privacy associated and it should be private by default" do
@ -49,8 +49,8 @@ describe Table do
table.name = 'Wadus table #2'
table.save
user.in_database do |user_database|
user_database.table_exists?('Wadus table'.to_sym).should be_false
user_database.table_exists?('Wadus table #2'.to_sym).should be_true
user_database.table_exists?('wadus_table'.to_sym).should be_false
user_database.table_exists?('wadus_table_2'.to_sym).should be_true
end
end

Loading…
Cancel
Save