stiki 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,3 +2,25 @@
2
2
  Place all the styles related to the matching controller here.
3
3
  They will automatically be included in application.css.
4
4
  */
5
+
6
+ .stiki {
7
+ .space {
8
+ .action {
9
+ float: right;
10
+
11
+ .update {
12
+ margin-right: 5px;
13
+ }
14
+
15
+ .delete {
16
+ border: 0;
17
+ background-color: white;
18
+ }
19
+ }
20
+
21
+
22
+ .title {
23
+ float: left;
24
+ }
25
+ }
26
+ }
@@ -8,6 +8,9 @@ module Stiki
8
8
  end
9
9
 
10
10
  # def show handled by PageController#index
11
+ def edit
12
+ @space = Space.find(params[:id])
13
+ end
11
14
 
12
15
  def create
13
16
  @space = Space.new(params[:space])
@@ -26,6 +29,26 @@ module Stiki
26
29
  redirect_to stiki_routes.spaces_path
27
30
  end
28
31
 
32
+ def update
33
+ @space = Space.find(params[:id])
34
+ @space.attributes = params[:space]
35
+
36
+ if Stiki.authenticate_by == :devise
37
+ author = Author.new
38
+ author.user = self.send( "current_#{Stiki::Helper.user_model_name}".to_sym )
39
+ @space.authors << author
40
+ end
41
+
42
+ if @space.save
43
+ flash[:notice] = "Space Updated"
44
+
45
+ redirect_to stiki_routes.spaces_path
46
+ else
47
+ flash[:error] = "Error creating new Space"
48
+ render :template => 'stiki/spaces/edit'
49
+ end
50
+ end
51
+
29
52
  def destroy
30
53
  @space = Space.find( params[:id] )
31
54
 
@@ -33,7 +56,7 @@ module Stiki
33
56
  flash[:error] = "Cannot delete a Wiki Space that has Wiki Pages"
34
57
  else
35
58
  @space.destroy
36
- flash[:info] = "The Space #{@space.name} has been deleted"
59
+ flash[:notice] = "The Space #{@space.name} has been deleted"
37
60
  end
38
61
 
39
62
  redirect_to stiki_routes.spaces_path
@@ -17,7 +17,9 @@ module Stiki
17
17
  end
18
18
 
19
19
  def user_name( author )
20
- author.user.send( Stiki.user_name_via ) if author && author.user
20
+ if Stiki.user_name_via
21
+ author.user.send( Stiki.user_name_via ) if author && author.user
22
+ end
21
23
  end
22
24
  end
23
25
  end
@@ -6,7 +6,13 @@ module Stiki
6
6
  friendly_id :name, use: :slugged
7
7
 
8
8
  has_many :pages
9
- has_many :authors, :as => :authorable
9
+ has_many :authors, :as => :authorable do
10
+ def <<(*authors)
11
+ # prevent duplicate authors
12
+ existing_users = proxy_association.owner.authors.map(&:user_id)
13
+ super( authors.select { |auth| !existing_users.include?( auth.user_id ) } )
14
+ end
15
+ end
10
16
  has_one :creator, :class_name => 'Author', :conditions => ["creator = ?", true], :as => :authorable
11
17
 
12
18
  attr_accessible :name
@@ -1,5 +1,5 @@
1
1
  <div class="row-fluid">
2
- <div class="span8">
2
+ <div class="span12">
3
3
  <div class="row-fluid well">
4
4
  <h2>Edit <%= @page.title %></h2>
5
5
  </div>
@@ -1,9 +1,8 @@
1
1
  <div class="row-fluid">
2
- <div class="span8">
2
+ <div class="span12">
3
3
  <div class="row-fluid well">
4
4
  <h2>New Page in <%= @space.name %></h2>
5
5
  </div>
6
-
7
6
  <div class="row-fluid well">
8
7
  <%= form_tag( stiki_routes.space_pages_path(@space), :class => 'form-horizontal' ) do |f| %>
9
8
  <%= render( :partial => 'stiki/pages/form', :locals => { :f => f, :page => @page } ) %>
@@ -0,0 +1,39 @@
1
+ <div class="stiki row-fluid">
2
+ <div class="span12">
3
+ <div class="row-fluid well">
4
+ <h2>Edit <%= @space.name %></h2>
5
+ </div>
6
+
7
+ <div class="row-fluid well">
8
+ <%= form_tag( stiki_routes.space_path(@space), :class => 'form-horizontal', :method => :put) do |f| %>
9
+ <fieldset>
10
+
11
+ <%- if @space.errors %>
12
+ <div class="control-group error">
13
+ <%- @space.errors.full_messages.each do |error| %>
14
+ <div class="error help-block">
15
+ <%= error %>
16
+ </div>
17
+ <% end -%>
18
+ </div>
19
+ <% end -%>
20
+
21
+ <div class="control-group">
22
+ <%= label_tag 'name', 'Name', :class => "control-label" %>
23
+ <div class="controls">
24
+ <input class="field input-xlarge span11" id="name" name="space[name]" value="<%= @space.name %>" size="30" type="text">
25
+ </div>
26
+ </div>
27
+ <div class="form-actions">
28
+ <div class="span4">
29
+ <%= submit_tag "Save", :class => "btn btn-primary btn-large" %>
30
+ </div>
31
+ <div class="span2">
32
+ <%= link_to 'Cancel', stiki_routes.spaces_path(), :class => 'btn' %>
33
+ </div>
34
+ </div>
35
+ </fieldset>
36
+ <% end -%>
37
+ </div>
38
+ </div>
39
+ </div>
@@ -1,57 +1,62 @@
1
- <%- @spaces.each do |space| %>
2
- <div class="row-fluid">
3
- <div class="span8 well">
4
- <div style="float:right">
5
- <%- if has_access( :update, @page ) %>
6
- <%= button_to "X", stiki_routes.space_path( space ), :method => :delete,
7
- :class => 'close', :confirm => 'Are you sure you want to delete this Wiki Space?' %>
8
- <% end -%>
1
+ <div class='stiki'>
2
+ <%- @spaces.each do |space| %>
3
+ <div class="row-fluid">
4
+ <div class="span8 well space">
5
+ <div class="action">
6
+ <%- if has_access( :update, @page ) %>
7
+ <%= link_to '<i class="icon-pencil"></i>'.html_safe, stiki_routes.edit_space_path( space ), :class => 'update close' %>
8
+ <% end %>
9
+ <%- if has_access( :delete, @page ) %>
10
+ <%= button_to 'x', stiki_routes.space_path( space ), :method => :delete,
11
+ :class => 'delete close', :confirm => 'Are you sure you want to delete this Wiki Space?' %>
12
+ <% end -%>
13
+ </div>
14
+ <div style="title">
15
+ <h2 ><%= link_to space.name, stiki_routes.space_pages_path(space) %></h2>
16
+ <% if space.creator %>
17
+ <h4 >Created by <%= user_name( space.creator ) %></h4>
18
+ <% end %>
19
+ </div>
20
+ </div>
9
21
  </div>
10
- <div style="float:left">
11
- <h2 ><%= link_to space.name, stiki_routes.space_pages_path(space) %></h2>
12
- <% if space.creator %>
13
- <h4 >Created by <%= user_name( space.creator ) %></h4>
14
- <% end %>
22
+ <% end -%>
23
+ <%- if has_access( :create, Stiki::Space ) %>
24
+ <%- if javascript_enabled %>
25
+ <div class="row-fluid create-space">
26
+ <div class="span8 well">
27
+ <a href="#" class="create-space-trigger">Create New Space</a>
28
+ </div>
15
29
  </div>
16
- </div>
17
- </div>
18
- <% end -%>
19
- <%- if has_access( :create, Stiki::Space ) %>
20
- <%- if javascript_enabled %>
21
- <div class="row-fluid create-space">
22
- <div class="span8 well">
23
- <a href="#" class="create-space-trigger">Create New Space</a>
24
- </div>
25
- </div>
26
- <% end -%>
27
- <div class="row-fluid create-space" style="<%= 'display:none' if javascript_enabled %>">
28
- <div class="span8">
29
- <div class="row-fluid">
30
- <%= form_tag( stiki_routes.spaces_path, :class => 'form-horizontal' ) do |f| %>
31
- <fieldset class="well">
32
- <h2>Create New Space</h2>
33
- <div class="control-group">
34
- <%= label_tag 'name', 'Name', :class => "control-label" %>
35
- <div class="controls">
36
- <input class="input-xlarge" id="name" name="space[name]" size="30" type="text">
30
+ <% end -%>
31
+ <div class="row-fluid create-space" style="<%= 'display:none' if javascript_enabled %>">
32
+ <div class="span8">
33
+ <div class="row-fluid">
34
+ <%= form_tag( stiki_routes.spaces_path, :class => 'form-horizontal' ) do |f| %>
35
+ <fieldset class="well">
36
+ <h2>Create New Space</h2>
37
+ <div class="control-group">
38
+ <%= label_tag 'name', 'Name', :class => "control-label" %>
39
+ <div class="controls">
40
+ <input class="input-xlarge" id="name" name="space[name]" size="30" type="text">
41
+ </div>
42
+ </div>
43
+ <div class="form-actions">
44
+ <%= submit_tag "Create", :class => "btn btn-primary btn-large" %>
45
+ <a href="#" class="create-space-trigger btn">Cancel</a>
37
46
  </div>
38
- </div>
39
- <div class="form-actions">
40
- <%= submit_tag "Create", :class => "btn btn-primary btn-large" %>
41
- <a href="#" class="create-space-trigger btn">Cancel</a>
42
- </div>
43
- </fieldset>
44
- <% end -%>
47
+ </fieldset>
48
+ <% end -%>
49
+ </div>
50
+ </div>
45
51
  </div>
46
- </div>
47
- </div>
48
- <%- if javascript_enabled %>
49
- <script type="text/javascript">
50
- $(function() {
51
- $('.create-space-trigger').click( function() {
52
- $('.create-space').slideToggle();
53
- });
54
- });
55
- </script>
56
- <% end -%>
57
- <% end -%>
52
+ <%- if javascript_enabled %>
53
+ <script type="text/javascript">
54
+ $(function() {
55
+ $('.create-space-trigger').click( function() {
56
+ $('.create-space').slideToggle();
57
+ });
58
+ });
59
+ </script>
60
+ <% end -%>
61
+ <% end -%>
62
+ </div>
@@ -7,9 +7,9 @@ module Stiki::Authenticate::Devise
7
7
  auth_required = Stiki.auth_mapping[base.controller_name.to_sym]
8
8
  if auth_required
9
9
  if auth_required == :all
10
- base.before_filter "authenticate_#{Stiki::Helper.user_model_name}!".to_sym
10
+ base.before_filter "authenticate_#{Stiki::Helper.user_model_name}!".to_sym, :if => lambda {|c| Stiki.authenticate_by == :devise }
11
11
  else
12
- base.before_filter "authenticate_#{Stiki::Helper.user_model_name}!".to_sym, auth_required
12
+ base.before_filter "authenticate_#{Stiki::Helper.user_model_name}!".to_sym, auth_required.merge( :if => lambda {|c| Stiki.authenticate_by == :devise } )
13
13
  end
14
14
  end
15
15
  else
@@ -4,6 +4,6 @@ module Stiki::Authorize::Cancan
4
4
  def self.included(base)
5
5
  require 'cancan'
6
6
  require 'cancan/ability'
7
- base.load_and_authorize_resource base.class.name
7
+ base.load_and_authorize_resource base.class.name, :if => lambda {|c| Stiki.authorize_by == :cancan }
8
8
  end
9
9
  end
data/lib/stiki/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Stiki
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -6,6 +6,7 @@ describe Stiki::PagesController do
6
6
  before do
7
7
  Stiki.config do |stiki|
8
8
  stiki.user_class = 'Author'
9
+ stiki.authorize_by = false
9
10
  end
10
11
  end
11
12
 
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'stiki/application_helper'
3
+ require 'ostruct'
4
+
5
+ describe Stiki::ApplicationHelper do
6
+ it "should expose Stiki routes" do
7
+ helper.stiki_routes.should eql Stiki::Engine.routes.url_helpers
8
+ end
9
+
10
+ it "should expose Stiki#javascript_enabled as javascript_enabled" do
11
+ Stiki.javascript_enabled = false
12
+ helper.javascript_enabled.should be_false
13
+
14
+ Stiki.javascript_enabled = true
15
+ helper.javascript_enabled.should be_true
16
+ end
17
+
18
+ it "should get user_name for user" do
19
+ Stiki.user_name_via = :name
20
+
21
+ author = OpenStruct.new
22
+ author.user = OpenStruct.new( :name => 'test' )
23
+
24
+ helper.user_name( author ).should eql 'test'
25
+ end
26
+
27
+ describe "#has_access" do
28
+ before do
29
+ view.stub!(:current_user).and_return( Author.new )
30
+ end
31
+
32
+ context "disabled" do
33
+ before do
34
+ Stiki.authorize_by = false
35
+ end
36
+
37
+ it "should always be true" do
38
+ helper.has_access(:action, nil ).should be_true
39
+ helper.has_access(nil, Author.new ).should be_true
40
+ end
41
+ end
42
+
43
+ context "enabled" do
44
+ before do
45
+ Stiki.authorize_by = :cancan
46
+ end
47
+
48
+ it "should be authorized for index" do
49
+ helper.has_access(:index, Stiki::Author ).should be_true
50
+ end
51
+
52
+ it "should not be authorized for create" do
53
+ helper.has_access(:create, Stiki::Author ).should be_false
54
+ end
55
+ end
56
+ end
57
+ end
@@ -9,7 +9,7 @@ describe Stiki::Authenticate::Devise do
9
9
  stiki.authenticate_by = :devise
10
10
  stiki.user_class = 'Author'
11
11
  stiki.authenticate_pages = :all
12
- stiki.authenticate_spaces = [:new, :create, :edit, :update]
12
+ stiki.authenticate_spaces = {:only => [:new, :create, :edit, :update]}
13
13
  end
14
14
  end
15
15
 
@@ -9,6 +9,7 @@ describe Stiki do
9
9
  Stiki.config do |stiki|
10
10
  stiki.authenticate_by = :devise
11
11
  stiki.user_class = 'Author'
12
+ stiki.user_name_via = :to_s
12
13
  stiki.authenticate_pages = {:only => [:blue, :green, :orange ] }
13
14
  stiki.authenticate_spaces = {:only => [:new, :create, :edit, :update] }
14
15
  end
@@ -18,7 +19,7 @@ describe Stiki do
18
19
  Stiki.authenticate_by.should eql :devise
19
20
  end
20
21
 
21
- it "should set default user_name_via" do
22
+ it "should set user_name_via" do
22
23
  Stiki.user_name_via.should eql :to_s
23
24
  end
24
25
 
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
4
4
  require 'rspec/rails'
5
5
  require 'rspec/autorun'
6
6
  require 'shoulda-matchers'
7
+ require 'cancan'
7
8
 
8
9
  # Requires supporting ruby files with custom matchers and macros, etc,
9
10
  # in spec/support/ and its subdirectories.
@@ -38,8 +39,7 @@ RSpec.configure do |config|
38
39
  # order dependency and want to debug it, you can fix the order by providing
39
40
  # the seed, which is printed after each run.
40
41
  # --seed 1234
41
- config.order = "random"
42
-
42
+ # config.order = "random"
43
43
 
44
44
  config.include FactoryGirl::Syntax::Methods
45
45
  end
@@ -49,6 +49,27 @@ class Author < ActiveRecord::Base
49
49
  self.table_name = "stiki_authors"
50
50
  end
51
51
 
52
+ class Ability
53
+ include CanCan::Ability
54
+
55
+ def initialize(user)
56
+ # Define abilities for the passed in user here. For example:
57
+ #
58
+ author ||= Author.new # guest user (not logged in)
59
+
60
+ can :manage, Stiki::Page
61
+ can :manage, Stiki::Space
62
+ can :index, Stiki::Author
63
+
64
+ end
65
+ end
66
+
67
+ class ActionView::TestCase::TestController
68
+ def current_user
69
+ Author.new
70
+ end
71
+ end
72
+
52
73
 
53
74
  # Shim the Stiki ApplicationController to get access to the filters
54
75
  # and stub the devise before_filter method
@@ -67,11 +88,15 @@ class Stiki::ApplicationController
67
88
  end
68
89
 
69
90
  def current_author
70
-
91
+ Author.new
71
92
  end
72
93
 
73
94
  def authenticate_author!
74
95
 
75
96
  end
97
+
98
+ def current_ability
99
+ @current_ability ||= Ability.new(current_author)
100
+ end
76
101
 
77
102
  end