creature_feature 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = CreatureFeature
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'CreatureFeature'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+ Bundler::GemHelper.install_tasks
28
+
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,7 @@
1
+ module Admin
2
+ class FeaturesController < ApplicationController
3
+ def index
4
+ @features = Feature.all
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,90 @@
1
+ module Admin
2
+ class RolesController < ApplicationController
3
+ def index
4
+ @roles = Role.all
5
+ end
6
+
7
+ def show
8
+ @role = Role.find(params[:id])
9
+ end
10
+
11
+ def new
12
+ @role = Role.new
13
+ @features = Feature.all
14
+ end
15
+
16
+ def edit
17
+ @role = Role.find(params[:id])
18
+ @features = Feature.all
19
+ end
20
+
21
+ def create
22
+ if params[:role]
23
+ fp_params = params[:role].delete(:feature_permissions) || []
24
+ else
25
+ fp_params = []
26
+ end
27
+
28
+ @role = Role.new(params[:role])
29
+ @features = Feature.all
30
+
31
+ success = false
32
+
33
+ if success = @role.save
34
+ fp_params.each do |fp|
35
+ next if fp['feature_id'].blank?
36
+ read_only = fp['read_only'] == fp['feature_id']
37
+ @role.feature_permissions << FeaturePermission.new(fp.merge(:role => @role, :read_only => read_only))
38
+ end
39
+
40
+ success = @role.save
41
+ end
42
+
43
+ if success
44
+ redirect_to(admin_role_url(@role), :notice => 'Role was successfully created.')
45
+ else
46
+ @role.destroy
47
+ render :action => 'new'
48
+ end
49
+ end
50
+
51
+ def update
52
+ if params[:role]
53
+ fp_params = params[:role].delete(:feature_permissions) || []
54
+ else
55
+ fp_params = []
56
+ end
57
+
58
+ @role = Role.find(params[:id])
59
+ @features = Feature.all
60
+
61
+ success = false
62
+
63
+ if success = @role.update_attributes(params[:role])
64
+ @role.features = []
65
+ fp_params.each do |fp|
66
+ next if fp['feature_id'].blank?
67
+ read_only = fp['read_only'] == fp['feature_id']
68
+ @role.feature_permissions << FeaturePermission.new(fp.merge(:role => @role, :read_only => read_only))
69
+ end
70
+
71
+ success = @role.save
72
+ end
73
+
74
+ if success
75
+ redirect_to(admin_role_url(@role), :notice => 'Role was successfully updated.')
76
+ else
77
+ render :action => 'edit'
78
+ end
79
+ end
80
+
81
+ def destroy
82
+ @role = Role.find(params[:id])
83
+ @role.destroy
84
+
85
+ notice = 'Role was successfully deleted.'
86
+
87
+ redirect_to(admin_roles_url, :notice => notice)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ module Admin
2
+ module FeaturesHelper
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Admin
2
+ module RolesHelper
3
+
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class Feature < ActiveRecord::Base
2
+ validates :name, :presence => true, :uniqueness => true
3
+
4
+ has_many :feature_permissions, :dependent => :destroy
5
+ has_many :roles, :through => :feature_permissions
6
+
7
+ def list_roles
8
+ roles.map(&:name).sort.join(', ')
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ class FeaturePermission < ActiveRecord::Base
2
+ validates_presence_of :role_id
3
+ validates_presence_of :feature_id
4
+
5
+ belongs_to :role
6
+ belongs_to :feature
7
+ end
@@ -0,0 +1,27 @@
1
+ class Role < ActiveRecord::Base
2
+ validates :name, :presence => true, :uniqueness => true
3
+
4
+ has_many :feature_permissions, :dependent => :destroy
5
+ has_many :features, :through => :feature_permissions
6
+
7
+ def read_only_features
8
+ list = []
9
+
10
+ feature_permissions.each do |fp|
11
+ list << fp.feature if fp.read_only
12
+ end
13
+
14
+ list
15
+ end
16
+
17
+ def list_features
18
+ list = feature_permissions.map do |fp|
19
+ name = I18n.t("admin.features.#{fp.feature.name}")
20
+ name = fp.feature.name if name.include? 'translation missing'
21
+ name += ' (Read-Only)' if fp.read_only
22
+ name
23
+ end
24
+
25
+ list.sort.join(', ')
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ %h1 Listing Features
2
+
3
+ %table
4
+ %tr
5
+ %th Name
6
+ %th Roles
7
+
8
+ - @features.each do |feature|
9
+ %tr
10
+ %td= feature.name
11
+ %td= feature.list_roles
@@ -0,0 +1,22 @@
1
+ = form_for @role, :url => url do |f|
2
+ -if @role.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@role.errors.count, "error")} prohibited this role from being saved:"
5
+ %ul
6
+ - @role.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ .field
10
+ = f.label :name
11
+ = f.text_field :name
12
+ - @features.each do |feature|
13
+ .field
14
+ = check_box_tag 'role[feature_permissions][][feature_id]', feature.id, @role.features.include?(feature),
15
+ :id => "role_feature_permissions_#{feature.id}_feature_id"
16
+ = label_tag "role_feature_permissions_#{feature.id}_feature_id", feature.name
17
+
18
+ = check_box_tag 'role[feature_permissions][][read_only]', feature.id, @role.read_only_features.include?(feature),
19
+ :id => "role_feature_permissions_#{feature.id}_read_only"
20
+ = label_tag "role_feature_permissions_#{feature.id}_read_only", 'Read-Only'
21
+ .actions
22
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing role
2
+
3
+ = render 'form', :url => admin_role_path(@role)
4
+
5
+ = link_to 'Show', admin_role_path(@role)
6
+ \|
7
+ = link_to 'Back', admin_roles_path
@@ -0,0 +1,19 @@
1
+ %h1 Listing Roles
2
+
3
+ %table
4
+ %tr
5
+ %th Name
6
+ %th
7
+ %th
8
+ %th
9
+
10
+ - @roles.each do |role|
11
+ %tr
12
+ %td= role.name
13
+ %td= link_to 'Show', admin_role_path(role)
14
+ %td= link_to 'Edit', edit_admin_role_path(role)
15
+ %td= link_to 'Destroy', admin_role_path(role), :confirm => 'Are you sure?', :method => :delete
16
+
17
+ %br
18
+
19
+ = link_to 'New Role', new_admin_role_path
@@ -0,0 +1,5 @@
1
+ %h1 New role
2
+
3
+ = render 'form', :url => admin_roles_path
4
+
5
+ = link_to 'Back', admin_roles_path
@@ -0,0 +1,13 @@
1
+ %p#notice= notice
2
+
3
+ %p
4
+ %b Name:
5
+ = @role.name
6
+
7
+ %p
8
+ %b Features:
9
+ = @role.list_features
10
+
11
+ = link_to 'Edit', edit_admin_role_path(@role)
12
+ \|
13
+ = link_to 'Back', admin_roles_path
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ namespace :admin do
3
+ get 'features' => 'features#index'
4
+
5
+ resources :roles
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class CreateFeatures < ActiveRecord::Migration
2
+ def change
3
+ create_table :features do |t|
4
+ t.string :name, :null => false
5
+ end
6
+
7
+ add_index :features, :name, :unique => true
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CreateRoles < ActiveRecord::Migration
2
+ def change
3
+ create_table :roles do |t|
4
+ t.string :name, :null => false
5
+ end
6
+
7
+ add_index :roles, :name, :unique => true
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class CreateFeaturePermissions < ActiveRecord::Migration
2
+ def change
3
+ create_table :feature_permissions do |t|
4
+ t.boolean :read_only, :default => false
5
+
6
+ t.integer :role_id, :null => false
7
+ t.integer :feature_id, :null => false
8
+ end
9
+
10
+ add_index :feature_permissions, [:role_id, :feature_id], :unique => true
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module CreatureFeature
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module CreatureFeature
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'creature_feature/engine'
2
+ require 'haml'
3
+
4
+ module CreatureFeature
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc 'Explaining what the task does'
2
+ # task :creature_feature do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,65 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
+
10
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
+
13
+ begin
14
+ require 'cucumber/rake/task'
15
+
16
+ namespace :cucumber do
17
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
+ t.fork = true # You may get faster startup if you set this to false
20
+ t.profile = 'default'
21
+ end
22
+
23
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
+ t.binary = vendored_cucumber_bin
31
+ t.fork = true # You may get faster startup if you set this to false
32
+ t.profile = 'rerun'
33
+ end
34
+
35
+ desc 'Run all features'
36
+ task :all => [:ok, :wip]
37
+
38
+ task :statsetup do
39
+ require 'rails/code_statistics'
40
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
+ end
43
+ end
44
+ desc 'Alias for cucumber:ok'
45
+ task :cucumber => 'cucumber:ok'
46
+
47
+ task :default => :cucumber
48
+
49
+ task :features => :cucumber do
50
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51
+ end
52
+
53
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54
+ task 'db:test:prepare' do
55
+ end
56
+
57
+ task :stats => 'cucumber:statsetup'
58
+ rescue LoadError
59
+ desc 'cucumber rake task not available (cucumber not installed)'
60
+ task :cucumber do
61
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,4 @@
1
+ desc 'Run guard'
2
+ task :guard do
3
+ sh %{ bundle exec guard --notify false}
4
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: creature_feature
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Earle Clubb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-18 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: &20407840 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *20407840
26
+ - !ruby/object:Gem::Dependency
27
+ name: haml-rails
28
+ requirement: &20406760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *20406760
37
+ - !ruby/object:Gem::Dependency
38
+ name: sqlite3
39
+ requirement: &20405660 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *20405660
48
+ - !ruby/object:Gem::Dependency
49
+ name: factory_girl_rails
50
+ requirement: &20405040 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *20405040
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec-rails
61
+ requirement: &20403860 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *20403860
70
+ - !ruby/object:Gem::Dependency
71
+ name: cucumber-rails
72
+ requirement: &20366200 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *20366200
81
+ - !ruby/object:Gem::Dependency
82
+ name: database_cleaner
83
+ requirement: &20364160 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *20364160
92
+ - !ruby/object:Gem::Dependency
93
+ name: launchy
94
+ requirement: &20334040 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *20334040
103
+ - !ruby/object:Gem::Dependency
104
+ name: guard
105
+ requirement: &20333260 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: *20333260
114
+ - !ruby/object:Gem::Dependency
115
+ name: guard-rspec
116
+ requirement: &20331440 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ type: :development
123
+ prerelease: false
124
+ version_requirements: *20331440
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-cucumber
127
+ requirement: &20329440 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: *20329440
136
+ description: Rails 3.1 engine which adds the ability to build roles from features
137
+ you create.
138
+ email:
139
+ - eclubb@valcom.com
140
+ executables: []
141
+ extensions: []
142
+ extra_rdoc_files: []
143
+ files:
144
+ - app/models/role.rb
145
+ - app/models/feature.rb
146
+ - app/models/feature_permission.rb
147
+ - app/helpers/admin/roles_helper.rb
148
+ - app/helpers/admin/features_helper.rb
149
+ - app/views/admin/features/index.html.haml
150
+ - app/views/admin/roles/new.html.haml
151
+ - app/views/admin/roles/_form.html.haml
152
+ - app/views/admin/roles/edit.html.haml
153
+ - app/views/admin/roles/show.html.haml
154
+ - app/views/admin/roles/index.html.haml
155
+ - app/controllers/admin/roles_controller.rb
156
+ - app/controllers/admin/features_controller.rb
157
+ - app/assets/stylesheets/admin/roles.css
158
+ - app/assets/stylesheets/admin/features.css
159
+ - app/assets/javascripts/admin/roles.js
160
+ - app/assets/javascripts/admin/features.js
161
+ - config/routes.rb
162
+ - config/cucumber.yml
163
+ - db/migrate/20111116151332_create_roles.rb
164
+ - db/migrate/20111115210509_create_features.rb
165
+ - db/migrate/20111116174017_create_feature_permissions.rb
166
+ - lib/tasks/cucumber.rake
167
+ - lib/tasks/guard.rake
168
+ - lib/tasks/creature_feature_tasks.rake
169
+ - lib/creature_feature.rb
170
+ - lib/creature_feature/version.rb
171
+ - lib/creature_feature/engine.rb
172
+ - MIT-LICENSE
173
+ - Rakefile
174
+ - README.rdoc
175
+ has_rdoc: true
176
+ homepage: ''
177
+ licenses: []
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ segments:
189
+ - 0
190
+ hash: -4057842884699446607
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ segments:
198
+ - 0
199
+ hash: -4057842884699446607
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 1.6.2
203
+ signing_key:
204
+ specification_version: 3
205
+ summary: Role/Feature engine for Rails 3.1.
206
+ test_files: []