API method for updating the tags of a table

1.0
Fernando Blat 14 years ago
parent 96fbfd1f02
commit 70034e10ef

@ -23,7 +23,7 @@ class Api::Json::TablesController < ApplicationController
respond_to do |format|
format.json do
begin
@table.update_fields(params, [:name])
@table.update_all(params)
render :nothing => true, :status => 200
rescue
render :json => { :errors => @table.errors.full_messages}.to_json, :status => 400

@ -6,8 +6,11 @@ class Table < Sequel::Model(:user_tables)
PRIVATE = 0
PUBLIC = 1
# Ignore mass-asigment on not allowed columns
self.strict_param_setting = false
# Allowed columns
set_allowed_columns(:name, :privacy)
set_allowed_columns(:name, :privacy, :tags)
## Callbacks
def validate

@ -80,4 +80,22 @@ feature "Tables JSON API" do
table.name.should == "My brand new name"
end
scenario "Update the tags of a table" do
user = create_user
table = create_table :user_id => user.id
authenticate_api user
put_json "/api/json/table/#{table.id}/update", {:tags => "tag1, tag2, tag3"}
response.status.should == 200
Tag.count.should == 3
tags = Tag.filter(:user_id => user.id, :table_id => table.id).all
tags.size.should == 3
tags.map(&:name).sort.should == %W{ tag1 tag2 tag3 }
put_json "/api/json/table/#{table.id}/update", {:tags => ""}
response.status.should == 200
Tag.count.should == 0
end
end

Loading…
Cancel
Save