Skip to content
Browse files

Remove sphere levels to simplify privacy

  • Loading branch information...
1 parent 6ea9162 commit c0205d58f73875beb323e53d38295d1b5566694b @atd atd committed Jul 12, 2011
View
0 app/assets/stylesheets/spheres.css → app/assets/stylesheets/relation_customs.css
File renamed without changes.
View
12 app/controllers/relation/customs_controller.rb
@@ -2,15 +2,5 @@ class Relation::CustomsController < InheritedResources::Base
before_filter :authenticate_user!
load_and_authorize_resource :class => Relation::Custom
- respond_to :js
-
- belongs_to :sphere, :optional => true
-
- def index
- # Must authorize index, because Cancan does not filter collection with conditions.
- # See https://github.com/ryanb/cancan/wiki/checking-abilities
- authorize! :read, parent.customs.new
-
- index!
- end
+ respond_to :html, :js
end
View
12 app/controllers/spheres_controller.rb
@@ -1,12 +0,0 @@
-class SpheresController < InheritedResources::Base
- before_filter :authenticate_user!
- load_and_authorize_resource
-
- respond_to :html, :js
-
- protected
-
- def begin_of_association_chain
- current_subject
- end
-end
View
41 app/models/actor.rb
@@ -56,11 +56,6 @@ class Actor < ActiveRecord::Base
:uniq => true
has_many :relations
- has_many :spheres
-
- has_many :relation_customs,
- :through => :spheres,
- :source => :customs
scope :alphabetic, order('actors.name')
@@ -146,6 +141,11 @@ def subject
activity_object.try(:object)
end
+ # All the {Relation relations} defined by this {Actor}
+ def relation_customs
+ relations.where(:type => 'Relation::Custom')
+ end
+
# A given relation defined and managed by this actor
def relation_custom(name)
relation_customs.find_by_name(name)
@@ -321,37 +321,6 @@ def receiver_activity_relations(subject)
Relation.allow(self, 'create', 'activity', :owner => subject)
end
- # Builds a hash of options their spheres as keys
- def grouped_activity_relations(subject)
- rels = activity_relations(subject)
-
- spheres =
- rels.map{ |r| r.respond_to?(:sphere) ? r.sphere : I18n.t('relation_public.name') }.uniq
-
- spheres.sort!{ |x, y|
- case x
- when Sphere
- case y
- when Sphere
- x.id <=> y.id
- else
- -1
- end
- else
- 1
- end
- }
-
- spheres.map{ |s|
- case s
- when Sphere
- [ s.name, rels.select{ |r| r.respond_to?(:sphere) && r.sphere == s }.sort.map{ |u| [ u.name, u.id ] } ]
- else
- [ s, rels.select{ |r| r.is_a?(Relation::Public) }.map{ |u| [ u.name, u.id ] } ]
- end
- }
- end
-
# Is this {Actor} allowed to create a comment on activity?
#
# We are allowing comments from everyone signed in by now
View
1 app/models/permission.rb
@@ -98,7 +98,6 @@ def description(type, relation = nil)
def description_options(relation)
{
- :sphere => relation.sphere.name,
:public => I18n.t('relation_public.name')
}.tap do |h|
case function
View
37 app/models/relation/custom.rb
@@ -13,16 +13,10 @@ class Relation::Custom < Relation
inspect
has_ancestry
- attr_protected :actor_id
-
- belongs_to :sphere
belongs_to :actor
- validates_presence_of :name, :sphere_id, :actor_id
- validates_uniqueness_of :name, :scope => :sphere_id
-
- before_validation :assign_parent, :on => :create
- before_validation :assign_actor, :on => :create
+ validates_presence_of :name, :actor_id
+ validates_uniqueness_of :name, :scope => :actor_id
class << self
# Relations configuration
@@ -40,13 +34,10 @@ def defaults_for(actor)
rels = {}
cfg_rels.each_pair do |name, cfg_rel|
- raise("Must associatiate relation #{ cfg_rel['name'] } to a sphere") if cfg_rel['sphere'].blank?
- sphere = actor.spheres.find_or_create_by_name(cfg_rel['sphere'])
-
rels[name] =
- create! :sphere => sphere,
- :receiver_type => cfg_rel['receiver_type'],
- :name => cfg_rel['name']
+ create! :actor => actor,
+ :name => cfg_rel['name'],
+ :receiver_type => cfg_rel['receiver_type']
if (ps = cfg_rel['permissions']).present?
ps.each do |p|
@@ -103,22 +94,4 @@ def stronger
def stronger_or_equal
path
end
-
- private
-
- # Before create callback
- #
- # Assign the last relation as parent if there are other custom relations in the sphere
- def assign_parent
- return if parent.present? || sphere.customs.blank?
-
- self.parent = sphere.customs.sort.last
- end
-
- # Before create callback
- #
- # Assign the sphere's actor
- def assign_actor
- self.actor = sphere.actor
- end
end
View
9 app/models/sphere.rb
@@ -1,9 +0,0 @@
-class Sphere < ActiveRecord::Base
- belongs_to :actor
-
- has_many :customs, :class_name => "Relation::Custom"
-
- validates_presence_of :name
- validates_uniqueness_of :name, :scope => :actor_id
-
-end
View
2 app/views/activities/_new.html.erb
@@ -19,7 +19,7 @@
</div>
<div id="activities_share_btn">
-<div id="securities"><%= select_tag :_relation_ids, grouped_options_for_select(current_subject.grouped_activity_relations(receiver)), :id => 'security', :multiple => nil %></div>
+ <div id="securities"><%= select_tag :_relation_ids, options_for_select(current_subject.activity_relations(receiver).sort.map{ |r| [ r.name, r.id ] }), :id => 'security', :multiple => nil %></div>
<%= submit_tag(t('share'), :class => "myButtonBlue", :id => "masterSubmitButton") %>
</div>
<% end %>
View
30 app/views/contacts/_form.html.erb
@@ -10,9 +10,6 @@
function checkBoxEnable(id) {
$('div[contain$=' + id + ']').addClass("checked-option");
-
- var sphere = $("#"+id).attr("optionOf");
- $(':checkbox[optionOf$='+sphere+']:checked:not(#'+id+')').checkBox('changeCheckStatus', false);
}
function checkBoxDisable(id) {
@@ -24,24 +21,21 @@
<%= form_for @contact do |f| %>
<%= hidden_field_tag "contact[relation_ids][]", "gotcha" %>
- <% current_subject.spheres.each do |sphere| %>
- <div class="sphere-name"><%= sphere.name %></div>
- <ul>
- <% sphere.customs.sort.each do |relation| %>
- <li>
- <div contain="<%= dom_id relation %>">
- <input id="<%= dom_id relation %>" name="contact[relation_ids][]" value="<%= relation.id %>" type="checkbox" optionOf="<%= sphere.name %>" <%= raw('checked="checked"') if @contact.relation_ids.include?(relation.id) %> />
- <label for="<%= dom_id relation %>">
- <%= relation.name %>
- </label>
- </div>
- </li>
- <% end %>
- </ul>
+ <ul>
+ <% current_subject.relation_customs.each do |relation| %>
+ <li>
+ <div contain="<%= dom_id relation %>">
+ <input id="<%= dom_id relation %>" name="contact[relation_ids][]" value="<%= relation.id %>" type="checkbox" <%= raw('checked="checked"') if @contact.relation_ids.include?(relation.id) %> />
+ <label for="<%= dom_id relation %>">
+ <%= relation.name %>
+ </label>
+ </div>
+ </li>
<% end %>
+ </ul>
<div id="contact-new">
- <%= link_to t('contact.type.new'), spheres_path %>
+ <%= link_to t('contact.type.new'), relation_customs_path %>
</div>
<div id="contact-message">
View
2 app/views/layouts/_settings.html.erb
@@ -10,7 +10,7 @@
<%= link_to t('settings.main'), settings_path, :id => "btn_menu_settings" %>
</li>
<li class="current">
- <%= link_to t('account.privacy'), spheres_path %>
+ <%= link_to t('account.privacy'), relation_customs_path %>
</li>
</ul>
</li>
View
4 app/views/relation/customs/_form.html.erb
@@ -1,7 +1,7 @@
-<% @custom ||= @sphere.customs.build %>
+<% @custom ||= Relation::Custom.new(:actor_id => current_subject.actor_id) %>
<%= form_for @custom, :remote => true do |f| %>
- <%= f.hidden_field :sphere_id %>
+ <%= f.hidden_field :actor_id %>
<% if @custom.errors.any? %>
<div id="error_explanation">
View
28 app/views/relation/customs/_index.html.erb
@@ -1,28 +0,0 @@
-<%= javascript_include_tag 'jquery-ui'%>
-
-<p class="sectionTitle"><%= raw t('relation_custom.in_sphere.choose', :name => h(@sphere.name)) %> </p>
-
-
-<div class="privacy_add_element">
- <div id="new_relation_custom_title_block">
- <a href="#"><span id="new_relation_custom_title" class="privacy_span_new"><%= t 'relation_custom.new' %></span></a>
- </div>
- <div id="new_relation_custom_input_block">
- <%= render :partial => 'relation/customs/form' %>
- </div>
-</div>
-
-<div id="relation_custom_list">
- <%= render :partial => 'relation/customs/list', :object => @customs %>
-</div>
-
-<%= javascript_tag do %>
- $(function() {
- $("#new_relation_custom_input_block").hide();
-
- $("#new_relation_custom_title").click(function() {
- $("#new_relation_custom_title_block").hide();
- $("#new_relation_custom_input_block").show();
- });
- })
-<% end %>
View
58 app/views/spheres/_jquery.erb → app/views/relation/customs/_jquery.erb
@@ -26,28 +26,9 @@ function checkBoxEnable(id) {
switch (checkBoxType(id)) {
- case "sphere":
- $(':checkbox[id^="sphere"]:checked:not(#' + id + ')').checkBox('changeCheckStatus', false);
-
- var sphereSelected = checkBoxId(id);
-
- $.ajax({
- url: "<%= relation_customs_path %>",
- context: document.body,
- data: { sphere_id: sphereSelected },
- dataType: "script"
- });
-
- break;
-
case "relation_custom":
$(':checkbox[id^="relation_custom"]:checked:not(#' + id + ')').checkBox('changeCheckStatus', false);
- var value = relations.length - checkBoxOrder(id) - 2;
- $("#slider-range").slider("value", value);
-
- $( "#relation" ).val(checkBoxValue(id));
-
$.ajax({
url: "<%= permissions_path %>",
context: document.body,
@@ -73,19 +54,10 @@ function checkBoxDisable(id) {
switch (checkBoxType(id)) {
- case "sphere":
- $("#permissions").html("");
- $("#permissions").hide();
- $("#relations").hide();
-
- break;
-
case "relation_custom":
$("#permissions").html("");
$("#permissions").hide();
- $("#slider-range").slider("value", relations.length - 1);
-
break;
case "permission":
@@ -98,33 +70,3 @@ function checkBoxDisable(id) {
}
}
-
-
-function initSlider() {
- /* TODO: get relations from checkboxOptions */
- relations.unshift("<%= t 'relation_public.name' %>");
- relations.push("<%= current_subject.name %>");
-
- $("#relation").val(relations[relations.length - 1]);
-
- $("#slider-range").slider({
- orientation: "vertical",
- range: "min",
- min: 0,
- max: relations.length - 1,
- step: 1,
- value: relations.length - 1,
- slide: function(event, ui) {
- $('#relation').val(relations[ui.value]);
- },
- stop: function(event, ui) {
- var order = relations.length - ui.value - 2;
- if (order >= 0 && order < relations.length - 2) {
- var id = '#' + checkBoxIdByOrder(order);
- $(id).checkBox('changeCheckStatus', true);
- } else {
- $(':checkbox[id^="relation_custom"]:checked').checkBox('changeCheckStatus', false);
- }
- }
- });
-};
View
35 app/views/relation/customs/_list.html.erb
@@ -1,36 +1,19 @@
-<table class="tableCheckBoxOptions">
-
- <tr><td colspan="2"><div class="slider-header"><%= current_subject.name %></div></td></tr>
-
- <tr><td rowspan="<%= list.size + 1 %>">
- <div class="slider-div">
- <p>
- <div id="slider-range"></div>
- </p>
- </div>
- </td>
- </tr>
-
- <% order = 0 %>
- <% list.sort.each do |r| %>
- <tr><td>
- <div contain=<%= dom_id r %> class="checkboxOptionLeft">
- <input id=<%= dom_id r %> type="checkbox"/>
- <label for="<%= dom_id r %>" order="<%= order %>"><%= r.name %></label>
+<table class="tableCheckBoxOptions">
+ <% list.each do |r| %>
+ <%= raw cycle("<tr><td>", "<td>", :name => "begin_cell") %>
+ <div contain="<%= dom_id(r) %>" class="checkboxOptionLeft">
+ <input id=<%= dom_id(r) %> type="checkbox"/>
+ <label for=<%= dom_id(r) %>><%=r.name%></label>
</div>
- </td></tr>
- <% order += 1 %>
+ <%= raw cycle("</td>", "</td></tr>", :name => "end_cell") %>
<% end %>
- <tr><td colspan="2"><div class="slider-footer"><%= t 'relation_public.name' %></div></td><tr>
+ <%= raw("</tr>") if list.size.odd? %>
+
</table>
<%= javascript_tag do %>
$(function() {
- relations = <%= list.sort.reverse.map{ |r| h(r.name) }.to_json.html_safe %>;
-
$('input[id^="relation_custom"]').checkBox();
-
- initSlider();
})
<% end %>
View
5 app/views/relation/customs/create.js.erb
@@ -1,7 +1,7 @@
<% if @custom.errors.present? %>
$('#new_relation_custom_input_block').html("<%= escape_javascript render(:partial => 'relation/customs/form') %>");
<% else %>
- // Hide #permissions
+ // Hide #relations and #permissions
$('#permissions').html("");
$('#permissions').hide();
@@ -10,9 +10,8 @@
$('#new_relation_custom_input_block').hide();
$('#new_relation_custom_title_block').show();
-
// Refresh list
- $('#relation_custom_list').html("<%= escape_javascript render(:partial => 'relation/customs/list', :object => @custom.sphere.customs.reload) %>");
+ $('#relation_customs_list').html("<%= escape_javascript render(:partial => 'relation/customs/list', :object => current_subject.relation_customs) %>");
// Select relation_custom
$('#' + '<%= dom_id @custom %>').checkBox('changeCheckStatus', true);
View
67 app/views/relation/customs/index.html.erb
@@ -0,0 +1,67 @@
+<% content_for :headers do %>
+ <%= stylesheet_link_tag "relation_customs.css", :media => "screen, projection" %>
+ <%= javascript_include_tag 'ui.checkbox'%>
+<% end %>
+
+<% toolbar :profile => current_subject, :option => 'contacts' %>
+
+<%= javascript_tag do %>
+ <%= render :partial => 'relation/customs/jquery' %>
+<% end %>
+
+<div id="wrapper_section">
+
+ <p class="pageTitle"><%= t 'relation_custom.title' %></p>
+
+ <div id="relation_customs" class="privacy_block_section first_block_section">
+ <p class="sectionTitle"><%= t 'relation_custom.choose' %></p>
+
+ <div class="privacy_add_element">
+ <div id="new_relation_custom_title_block">
+ <a href="#"><span id="new_relation_custom_title" class="privacy_span_new"><%= t('relation_custom.new') %></span></a>
+ </div>
+ <div id="new_relation_custom_input_block">
+ <%= render :partial => 'relation/customs/form' %>
+ </div>
+ </div>
+
+ <%= javascript_tag do %>
+ $(function() {
+ $("#new_relation_custom_input_block").hide();
+
+ $("#new_relation_custom_title").click(function() {
+ $("#new_relation_custom_title_block").hide();
+ $("#new_relation_custom_input_block").show();
+ });
+
+ $("#loading").hide();
+
+ $("#loading").ajaxStart(function(){
+ $(this).show();
+ });
+
+ $("#loading").ajaxStop(function(){
+ $(this).hide();
+ });
+
+ })
+ <% end %>
+
+ <div id="relation_customs_list">
+ <%= render :partial => 'relation/customs/list', :object => @customs %>
+ </div>
+
+</div>
+
+
+ <div id="permissions" class="privacy_block_section">
+ </div>
+
+ <div id="loading"></div>
+
+ <%= javascript_tag do %>
+ $(function() {
+ $("#permissions").hide();
+ })
+ <% end %>
+</div>
View
2 app/views/relation/customs/index.js.erb
@@ -1,2 +0,0 @@
-$('#relations').html("<%= escape_javascript render(:partial => 'index') %>");
-$('#relations').show();
View
28 app/views/spheres/_form.html.erb
@@ -1,28 +0,0 @@
-<% @sphere ||= Sphere.new %>
-
-<%= form_for @sphere, :remote => true do |f| %>
-
- <% if @sphere.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@sphere.errors.count, "error") %> prohibited this sphere from being saved:</h2>
-
- <ul>
- <% @sphere.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <p><%= f.text_field :name, :class => "privacy_input_new", :size => 20 %></p>
- <%= f.submit nil, :class => "button" %>
- <button class="button" id="cancel_new_sphere" ><%= t('button.cancel') %></button>
-<% end %>
-
-<%= javascript_tag do %>
- $("#cancel_new_sphere").click(function() {
- $("#new_sphere_input_block").hide();
- $("#new_sphere_title_block").show();
- return false;
- });
-<% end %>
View
19 app/views/spheres/_list.html.erb
@@ -1,19 +0,0 @@
-<table class="tableCheckBoxOptions">
- <% list.each do |sphere| %>
- <%= raw cycle("<tr><td>", "<td>", :name => "begin_cell") %>
- <div contain="<%= dom_id(sphere) %>" class="checkboxOptionLeft">
- <input id=<%= dom_id(sphere) %> type="checkbox"/>
- <label for=<%= dom_id(sphere) %>><%=sphere.name%></label>
- </div>
- <%= raw cycle("</td>", "</td></tr>", :name => "end_cell") %>
- <% end %>
-
- <%= raw("</tr>") if list.size.odd? %>
-
-</table>
-
-<%= javascript_tag do %>
- $(function() {
- $('input[id^="sphere"]').checkBox();
- })
-<% end %>
View
20 app/views/spheres/create.js.erb
@@ -1,20 +0,0 @@
-<% if @sphere.errors.present? %>
- $('#new_sphere_input_block').html("<%= escape_javascript render(:partial => 'spheres/form') %>");
-<% else %>
- // Hide #relations and #permissions
- $('#permissions').html("");
- $('#permissions').hide();
- $('#relations').hide();
-
- // Restore form
- $('#sphere_name').val('');
- $('#new_sphere_input_block').hide();
- $('#new_sphere_title_block').show();
-
- // Refresh list
- $('#spheres_list').html("<%= escape_javascript render(:partial => 'spheres/list', :object => current_subject.spheres) %>");
-
- // Select sphere
- $('#' + '<%= dom_id @sphere %>').checkBox('changeCheckStatus', true);
-<% end %>
-
View
74 app/views/spheres/index.html.erb
@@ -1,74 +0,0 @@
-<% content_for :headers do %>
- <%= stylesheet_link_tag "spheres.css", :media => "screen, projection" %>
- <%= stylesheet_link_tag "jquery.ui.slider.css", :media => "screen, projection" %>
- <%= stylesheet_link_tag "jquery.ui.slidertheme.css", :media => "screen, projection" %>
- <%= javascript_include_tag 'ui.checkbox'%>
-<% end %>
-
-<% toolbar :profile => current_subject, :option => 'contacts' %>
-
-<%= javascript_tag do %>
- <%= render :partial => 'spheres/jquery' %>
-<% end %>
-
-<div id="wrapper_section">
-
- <p class="pageTitle"><%= t 'sphere.title' %></p>
-
- <div id="spheres" class="privacy_block_section first_block_section">
- <p class="sectionTitle"><%= t 'sphere.choose' %></p>
-
- <div class="privacy_add_element">
- <div id="new_sphere_title_block">
- <a href="#"><span id="new_sphere_title" class="privacy_span_new"><%= t('sphere.new') %></span></a>
- </div>
- <div id="new_sphere_input_block">
- <%= render :partial => 'spheres/form' %>
- </div>
- </div>
-
- <%= javascript_tag do %>
- $(function() {
- $("#new_sphere_input_block").hide();
-
- $("#new_sphere_title").click(function() {
- $("#new_sphere_title_block").hide();
- $("#new_sphere_input_block").show();
- });
-
- $("#loading").hide();
-
- $("#loading").ajaxStart(function(){
- $(this).show();
- });
-
- $("#loading").ajaxStop(function(){
- $(this).hide();
- });
-
- })
- <% end %>
-
- <div id="spheres_list">
- <%= render :partial => 'spheres/list', :object => @spheres %>
- </div>
-
-</div>
-
-
- <div id="relations" class="privacy_block_section">
- </div>
-
-
- <div id="permissions" class="privacy_block_section">
- </div>
-
- <div id="loading"></div>
-
- <%= javascript_tag do %>
- $(function() {
- $("#relations").hide();
- $("#permissions").hide();
- })
- <% end %>
-</div>
View
20 config/locales/en.yml
@@ -150,8 +150,6 @@ en:
help: "Help"
helpers:
submit:
- sphere:
- create: "Save"
relation_custom:
create: "Save"
home: "Home"
@@ -263,17 +261,17 @@ en:
detailed:
create:
activity:
- same_level: "Post to \"%{sphere}\" wall at %{relation} level"
- same_and_lower_levels: "Post to \"%{sphere}\" wall as %{relations} and %{public}"
+ same_level: "Post to \"%{relation}\" wall"
+ same_and_lower_levels: "Post to \"%{relations}\" and %{public}"
destroy:
activity:
- nil: "Delete the activities posted to \"%{sphere}\" wall by this %{relation}"
+ nil: "Delete the activities posted to \"%{relation}\" wall"
follow:
nil:
nil: "Activities of the contacts at %{relation} level will appear in our home wall"
read:
activity:
- same_and_lower_levels: "Read posts in \"%{sphere}\" wall at levels %{relations} and %{public}"
+ same_and_lower_levels: "Read posts in \"%{relations}\" wall and %{public}"
tie:
same_and_lower_levels:
"See contacts in levels: %{relations} and %{public}"
@@ -296,9 +294,9 @@ en:
one: "Product"
other: "Products"
relation_custom:
- in_sphere:
- choose: "2. Levels in <strong>%{name}</strong> sphere"
- new: "+ New level"
+ title: "Privacy & context"
+ choose: "1. Choose stream"
+ new: "+ New stream"
relation_public:
name: "Public"
required: "* These fields are required"
@@ -327,10 +325,6 @@ en:
sign_out: "Sign out"
sign_up: "Sign up"
socialstream: "SocialStream"
- sphere:
- title: "Privacy & context"
- choose: "1. Choose sphere"
- new: '+ New sphere'
sure: "Are you sure?"
time:
ago: "%{time} ago"
View
1 config/routes.rb
@@ -29,7 +29,6 @@
resources :contacts
- resources :spheres
namespace "relation" do
resources :customs
end
View
30 db/migrate/20110712090343_remove_spheres.rb
@@ -0,0 +1,30 @@
+class RemoveSpheres < ActiveRecord::Migration
+ def up
+ remove_foreign_key "relations", :name => "relations_on_sphere_id"
+
+ remove_foreign_key "spheres", :name => "spheres_on_actor_id"
+
+ remove_column :relations, :sphere_id
+
+ drop_table :spheres
+ end
+
+ def down
+ add_column :relations, :sphere_id, :integer
+
+ add_index "relations", "sphere_id"
+
+ create_table "spheres", :force => true do |t|
+ t.string "name"
+ t.integer "actor_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "spheres", "actor_id"
+
+ add_foreign_key "relations", "spheres", :name => "relations_on_sphere_id"
+
+ add_foreign_key "spheres", "actors", :name => "spheres_on_actor_id"
+ end
+end
View
3 lib/social_stream/ability.rb
@@ -93,8 +93,7 @@ def initialize(subject)
end
# Privacy
- can [:create, :read, :update, :destroy], Sphere, :actor_id => subject.try(:actor_id)
- can [:create, :read, :update, :destroy], Relation::Custom, :sphere => { :actor_id => subject.try(:actor_id) }
+ can [:create, :read, :update, :destroy], Relation::Custom, :actor_id => subject.try(:actor_id)
end
end
end
View
3 spec/controllers/permissions_controller_spec.rb
@@ -14,8 +14,7 @@
context "with an existing relation" do
before do
- @sphere = Factory(:sphere, :actor_id => @user.actor_id)
- @relation = Factory(:relation_custom, :sphere_id => @sphere.id)
+ @relation = Factory(:relation_custom, :actor_id => @user.actor_id)
end
it "should render index" do
View
131 spec/controllers/relation_customs_controller_spec.rb
@@ -1,103 +1,112 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Relation::CustomsController do
- include SocialStream::TestHelpers::Controllers
-
render_views
- describe "when authenticated" do
- before do
- @user = Factory(:user)
+ describe "when Anonymous" do
+ context "faking a new relation" do
+ it "should not create" do
+ post :create, :custom => Factory.attributes_for(:relation_custom)
- sign_in @user
+ response.should redirect_to(:new_user_session)
+ end
end
- context "with an existing sphere" do
+ context "an existing relation" do
before do
- @sphere = Factory(:sphere, :actor_id => @user.actor_id)
+ @relation = Factory(:relation_custom)
end
- it "should render index" do
- get :index, :sphere_id => @sphere.id, :format => "js"
+ it "should not update" do
+ put :update, :id => @relation.to_param, :custom => { :name => 'Testing' }
- response.should be_success
+ assigns(:custom).should be_blank
+ response.should redirect_to(:new_user_session)
end
- context "a new relation" do
- it "should be created" do
- count = Relation::Custom.count
+ it "should not destroy" do
+ count = Relation.count
+ begin
+ delete :destroy, :id => @relation.to_param
+ rescue CanCan::AccessDenied
+ end
- post :create, :custom => { :name => "Test create", :sphere_id => @sphere.id }, :format => 'js'
+ relation = assigns(:custom)
- relation = assigns(:custom)
+ Relation.count.should eq(count)
+ end
- Relation::Custom.count.should eq(count + 1)
- relation.should be_valid
- response.should be_success
- end
+ end
+ end
- end
- context "a existing own relation" do
- before do
- @relation = Factory(:relation_custom, :sphere_id => @sphere.id)
- @relation.reload
- end
+ describe "when authenticated" do
+ before do
+ @user = Factory(:user)
+
+ sign_in @user
+ end
- it "should allow updating" do
- attrs = { :name => "Updating own" }
+ it "should render index" do
+ get :index
- put :update, :id => @relation.to_param, :relation_custom => attrs, :format => 'js'
+ response.should be_success
+ end
- relation = assigns(:custom)
+ context "a new own relation" do
+ it "should be created" do
+ count = Relation::Custom.count
-# relation.should_receive(:update_attributes).with(attrs)
- relation.should be_valid
- response.should be_success
- end
+ post :create, :custom => { :name => "Test create", :actor_id => @user.actor_id }, :format => 'js'
+
+ relation = assigns(:custom)
- it "should allow destroying" do
- pending "Delete relations"
+ Relation::Custom.count.should eq(count + 1)
+ relation.should be_valid
+ response.should be_success
+ end
+ end
- count = Relation::Custom.count
+ context "a new fake relation" do
+ it "should not be created" do
+ count = Relation.count
+ begin
+ post :create, :custom => Factory.attributes_for(:relation_custom)
- delete :destroy, :id => @relation.to_param, :format => :js
+ assert false
+ rescue CanCan::AccessDenied
+ assigns(:custom).should be_new_record
- Relation::Custom.count.should eq(count - 1)
+ Relation.count.should eq(count)
end
end
-
end
- context "with a fake sphere" do
+ context "a existing own relation" do
before do
- @sphere = Factory(:sphere)
+ @relation = Factory(:relation_custom, :actor => @user.actor)
end
- it "should not render index" do
- begin
- get :index, :sphere_id => @sphere.id, :format => "js"
+ it "should allow updating" do
+ attrs = { :name => "Updating own" }
- # Should not get here
- assert false
- rescue CanCan::AccessDenied
- assigns(:customs).should be_blank
- end
+ put :update, :id => @relation.to_param, :relation_custom => attrs, :format => 'js'
+
+ relation = assigns(:custom)
+
+# relation.should_receive(:update_attributes).with(attrs)
+ relation.should be_valid
+ response.should be_success
end
- context "a new relation" do
- it "should belong to user" do
- count = Relation::Custom.count
+ it "should allow destroying" do
+ pending "Delete relations"
- begin
- post :create, :relation_custom => { :name => "Test create", :sphere_id => @sphere.id }, :format => 'js'
+ count = Relation::Custom.count
- assert false
- rescue CanCan::AccessDenied
+ delete :destroy, :id => @relation.to_param, :format => :js
- Relation::Custom.count.should eq(count)
- end
- end
+ Relation::Custom.count.should eq(count - 1)
end
end
@@ -126,8 +135,6 @@
end
end
end
-
-
end
end
View
116 spec/controllers/spheres_controller_spec.rb
@@ -1,116 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe SpheresController do
- include SocialStream::TestHelpers::Controllers
-
- render_views
-
- describe "when Anonymous" do
- context "faking a new sphere" do
- before do
- model_attributes[:actor_id] = Factory(:user).actor_id
- end
-
- it "should not create" do
- post :create, attributes
-
- response.should redirect_to(:new_user_session)
- end
- end
-
- context "an existing sphere" do
- before do
- @current_model = Factory(:sphere)
- end
-
- it "should not update" do
- put :update, updating_attributes
-
- assigns(:sphere).should be_blank
- response.should redirect_to(:new_user_session)
- end
-
- it_should_behave_like "Deny Destroying"
- end
- end
-
- describe "when authenticated" do
- before do
- @user = Factory(:user)
-
- sign_in @user
- end
-
- it "should render index" do
- get :index
-
- assert_response :success
- end
-
- context "a new own sphere" do
- before do
- model_attributes[:actor_id] = @user.actor_id
- end
-
- it_should_behave_like "Allow Creating"
- end
-
- context "a new fake sphere" do
- before do
- model_attributes[:actor_id] = Factory(:user).actor_id
- end
-
- it "should not be created" do
- count = Sphere.count
- begin
- post :create, attributes
-
- assert false
- rescue CanCan::AccessDenied
- assigns(:sphere).should be_new_record
-
- Sphere.count.should eq(count)
- end
- end
- end
-
- context "a external sphere" do
- before do
- @current_model = Factory(:sphere)
- end
-
- it "should not be found on update" do
- begin
- put :update, updating_attributes
-
- assert false
- rescue ActiveRecord::RecordNotFound
- assigns(:sphere).should be_nil
- end
- end
-
- it "should not be found on destroy" do
- begin
- delete :destroy, :id => @current_model.to_param
-
- assert false
- rescue ActiveRecord::RecordNotFound
- assigns(:sphere).should be_nil
- end
- end
- end
-
-
- context "a existing own sphere" do
- before do
- @current_model = Factory(:sphere, :actor_id => @user.actor_id)
- end
-
- # This is not working, because of updating attributes. Do not know why
- # it_should_behave_like "Allow Updating"
- it_should_behave_like "Allow Destroying"
- end
-
- end
-end
-
View
2 spec/factories/relation_custom.rb
@@ -1,4 +1,4 @@
Factory.define(:relation_custom, :class => Relation::Custom) do |c|
c.sequence(:name) { |n| "Relation custom #{ n }" }
- c.association :sphere
+ c.association :actor
end
View
5 spec/factories/sphere.rb
@@ -1,5 +0,0 @@
-Factory.define :sphere do |s|
- s.sequence(:name) { |n| "Sphere #{ n }" }
- s.association :actor
-end
-
View
14 spec/models/relation_custom_spec.rb
@@ -1,14 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-
-describe Relation::Custom do
- it "should assign parent" do
- parent = Factory(:relation_custom)
- sphere = parent.sphere
-
- r = Relation::Custom.create! :name => "test",
- :sphere_id => sphere.id
-
- r.parent.should eq(parent)
- end
-end
-

0 comments on commit c0205d5

Please sign in to comment.
Something went wrong with that request. Please try again.