admini 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1ca246591999312d4fb645e07db0908545a3d0d
4
- data.tar.gz: fea1ddd7562e51df56f487d21b5773df2bfca5e7
3
+ metadata.gz: b54a44f81ceacbb98218300cb0915549dd4c521a
4
+ data.tar.gz: 2efb51f3cc96b43615c00c772d266ae267d52932
5
5
  SHA512:
6
- metadata.gz: 6a0353dcbf993d93d98caac46c09d17313d1008093fe01a25a5416c548e0c4bc12b5d9d32a5ee2fa591a3956971307339780ff5bd044a61d1a4d1d602ebb0696
7
- data.tar.gz: e06b9a436f94a80b041adeabbfaa1cd873f96aca71988111b9623224731b5f17c3634c567342188ad3294d3c41c9b6a3f6c95aa98ada4ae60f960db21b157704
6
+ metadata.gz: ed58c33259ae1e04a3426a5b5cba4de0e7c7b02b39a51de3e6668ee268258b17fea6a10bb31c67aec7a084207764123d301d2a2e76d130be2f1ad6213b7c0182
7
+ data.tar.gz: 9729485865f0afc978230496c313253e9b18034fe46c82232451670173d7fb43a5cb9e3d62ac5d1e4c0187caf3d4290cc3cbfb6f3e659391dedf8aaef98c1e7d
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Admini
2
2
 
3
+ [![Build Status](https://travis-ci.org/kami-zh/admini.svg?branch=master)](https://travis-ci.org/kami-zh/admini)
3
4
  [![Gem Version](https://badge.fury.io/rb/admini.svg)](https://badge.fury.io/rb/admini)
4
5
 
5
6
  Admini is a minimal administration framework for Ruby on Rails application.
@@ -12,6 +13,8 @@ Admini is the simplest framework, so you can create administration page accordin
12
13
 
13
14
  **Note**: Admini is still under development, and there may be breaking changes to the API.
14
15
 
16
+ ![](https://raw.githubusercontent.com/kami-zh/admini/master/docs/screenshot.png)
17
+
15
18
  ## Table of contents
16
19
 
17
20
  - [Demo](#demo)
@@ -37,9 +40,9 @@ Admini is the simplest framework, so you can create administration page accordin
37
40
  ## Demo
38
41
 
39
42
  You can try an administration page built with Admini at following link.
40
- The code of the demo can be found [here]().
43
+ The code of the demo can be found [here](https://github.com/kami-zh/admini-demo).
41
44
 
42
- - http://example.com
45
+ - https://admini.herokuapp.com/admin
43
46
 
44
47
  ## Installation
45
48
 
data/Rakefile CHANGED
@@ -1,3 +1,7 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
2
3
 
3
4
  Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -14,9 +14,17 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.files = `git ls-files -z`.split("\x0")
16
16
 
17
- s.add_dependency 'actionpack'
17
+ s.add_dependency 'actionview'
18
18
  s.add_dependency 'activesupport'
19
- s.add_dependency 'jquery-rails'
20
19
  s.add_dependency 'simple_form'
21
20
  s.add_dependency 'kaminari'
21
+ s.add_dependency 'jquery-rails'
22
+
23
+ s.add_development_dependency 'actionpack'
24
+ s.add_development_dependency 'activerecord'
25
+ s.add_development_dependency 'rspec-rails'
26
+ s.add_development_dependency 'sqlite3'
27
+ s.add_development_dependency 'rails-controller-testing'
28
+ s.add_development_dependency 'capybara'
29
+ s.add_development_dependency 'database_cleaner'
22
30
  end
@@ -104,6 +104,13 @@ select {
104
104
  vertical-align: middle;
105
105
  }
106
106
 
107
+ .error {
108
+ display: block;
109
+ margin-top: 4px;
110
+ color: #e00;
111
+ font-size: .8rem;
112
+ }
113
+
107
114
  .pagination {
108
115
  margin-bottom: 20px;
109
116
  }
@@ -4,8 +4,6 @@ module Admini
4
4
  module Resources
5
5
  extend ActiveSupport::Concern
6
6
 
7
- include ActionView::Helpers::FormOptionsHelper
8
-
9
7
  included do
10
8
  before_action :load_resources, only: :index
11
9
  before_action :load_resource, only: [:edit, :update, :show, :destroy]
@@ -13,10 +11,11 @@ module Admini
13
11
  before_action :search_resources, only: :index
14
12
  before_action :authorize
15
13
 
16
- helper_method :resource_name,
17
- :index_attributes,
14
+ helper_method :index_attributes,
18
15
  :new_attributes,
16
+ :create_attributes,
19
17
  :edit_attributes,
18
+ :update_attributes,
20
19
  :show_attributes,
21
20
  :search_attributes,
22
21
  :enum_attributes,
@@ -24,10 +23,9 @@ module Admini
24
23
  :can_read?,
25
24
  :can_update?,
26
25
  :can_delete?,
27
- :enable_action?,
28
26
  :render_attribute,
29
- :resource_object,
30
- :search_options
27
+ :resource_name,
28
+ :resource_object
31
29
 
32
30
  layout 'admini/layouts/application'
33
31
  end
@@ -98,13 +96,7 @@ module Admini
98
96
  end
99
97
 
100
98
  def resource_params
101
- attributes = case action_name
102
- when 'create'
103
- new_attributes
104
- when 'update'
105
- edit_attributes
106
- end
107
- params.require(resource_name).permit(attributes)
99
+ params.require(resource_name).permit(send("#{action_name}_attributes"))
108
100
  end
109
101
 
110
102
  def search_resources
@@ -126,10 +118,18 @@ module Admini
126
118
  %i()
127
119
  end
128
120
 
121
+ def create_attributes
122
+ new_attributes
123
+ end
124
+
129
125
  def edit_attributes
130
126
  new_attributes
131
127
  end
132
128
 
129
+ def update_attributes
130
+ edit_attributes
131
+ end
132
+
133
133
  def search_attributes
134
134
  %i()
135
135
  end
@@ -181,20 +181,8 @@ module Admini
181
181
  end
182
182
  end
183
183
 
184
- def enable_action?(action)
185
- routes.include?(controller: controller_path, action: action.to_s)
186
- end
187
-
188
- def routes
189
- @routes ||= Rails.application
190
- .routes
191
- .routes
192
- .map(&:defaults)
193
- .reject(&:blank?)
194
- end
195
-
196
184
  def resource_object
197
- defined?(super) ? super : [:admin, @resource]
185
+ defined?(super) ? super : [:admin, resource]
198
186
  end
199
187
 
200
188
  def render_attribute(resource, attribute)
@@ -205,14 +193,6 @@ module Admini
205
193
  end
206
194
  end
207
195
 
208
- def search_options
209
- options = []
210
- search_attributes.each do |attribute|
211
- options << [t("activerecord.attributes.#{resource_name}.#{attribute}"), attribute]
212
- end
213
- options_for_select(options)
214
- end
215
-
216
196
  def paginates_per
217
197
  defined?(super) ? super : 25
218
198
  end
@@ -0,0 +1,29 @@
1
+ module Admini
2
+ module ApplicationHelper
3
+ include ActionView::Helpers::TranslationHelper
4
+ include ActionView::Helpers::FormOptionsHelper
5
+ include ActiveSupport::Multibyte::Unicode
6
+
7
+ def enable_action?(action)
8
+ routes.include?(controller: controller_path, action: action.to_s)
9
+ end
10
+
11
+ def search_options
12
+ options = []
13
+ search_attributes.each do |attribute|
14
+ options << [t("activerecord.attributes.#{resource_name}.#{attribute}", default: attribute.to_s.camelize), attribute]
15
+ end
16
+ options_for_select(options)
17
+ end
18
+
19
+ private
20
+
21
+ def routes
22
+ @routes ||= Rails.application
23
+ .routes
24
+ .routes
25
+ .map(&:defaults)
26
+ .reject(&:blank?)
27
+ end
28
+ end
29
+ end
Binary file
@@ -1,3 +1,3 @@
1
1
  module Admini
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Admin::PostsController, type: :controller do
4
+ before do
5
+ Post.create(title: 'foo', content: 'foo')
6
+ Post.create(title: 'bar', content: 'bar')
7
+ Post.create(title: 'baz', content: 'baz')
8
+ end
9
+
10
+ describe '#resources' do
11
+ it 'returns all posts' do
12
+ get :index
13
+ expect(assigns(:resources).count).to eq 3
14
+ end
15
+ end
16
+
17
+ describe '#resource' do
18
+ it 'returns a post' do
19
+ get :show, params: { id: 1 }
20
+ expect(assigns(:resource).title).to eq 'foo'
21
+ end
22
+ end
23
+
24
+ describe '#build_resource' do
25
+ it 'creates a Post instance' do
26
+ get :new
27
+ expect(assigns(:resource)).to be_a_kind_of(Post)
28
+ expect(assigns(:resource)).not_to be_persisted
29
+ end
30
+
31
+ it 'creates a Post instance with params' do
32
+ post :create, params: { post: { title: 'qux', content: 'qux' } }
33
+ expect(assigns(:resource).title).to eq 'qux'
34
+ end
35
+ end
36
+
37
+ describe '#search_resources' do
38
+ it 'returns posts which includes keyword' do
39
+ get :index, params: { attribute: 'title', value: 'ba' }
40
+ expect(assigns(:resources).count).to eq 2
41
+ end
42
+ end
43
+
44
+ describe '#authorize' do
45
+ it 'raises error when access to prohibited action' do
46
+ expect { delete :destroy, params: { id: 1 } }.to raise_error(Admini::AuthorizationError)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,98 @@
1
+ require 'action_controller/railtie'
2
+ require 'active_record'
3
+ require 'admini'
4
+
5
+ module Dummy
6
+ class Application < Rails::Application
7
+ config.secret_key_base = 'abcdefghijklmnopqrstuvwxyz0123456789'
8
+ config.eager_load = false
9
+ end
10
+ end
11
+
12
+ Dummy::Application.initialize!
13
+
14
+ ActiveRecord::Base.establish_connection(
15
+ adapter: 'sqlite3',
16
+ database: ':memory:'
17
+ )
18
+
19
+ #
20
+ # Migrates
21
+ #
22
+
23
+ class CreateUsers < ActiveRecord::Migration
24
+ def change
25
+ create_table :users do |t|
26
+ t.timestamps null: false
27
+ end
28
+ end
29
+ end
30
+
31
+ class CreatePosts < ActiveRecord::Migration
32
+ def change
33
+ create_table :posts do |t|
34
+ t.string :title, null: false
35
+ t.text :content, null: false
36
+ t.integer :status, null: false, default: 0
37
+ t.timestamps null: false
38
+ end
39
+ end
40
+ end
41
+
42
+ CreateUsers.new.change
43
+ CreatePosts.new.change
44
+
45
+ #
46
+ # Routes
47
+ #
48
+
49
+ Dummy::Application.routes.draw do
50
+ namespace :admin do
51
+ resources :users, only: [:index, :show]
52
+ resources :posts
53
+ end
54
+ end
55
+
56
+ #
57
+ # Models
58
+ #
59
+
60
+ class User < ActiveRecord::Base; end
61
+
62
+ class Post < ActiveRecord::Base
63
+ enum status: { draft: 0, published: 10 }
64
+ end
65
+
66
+ #
67
+ # Controllers
68
+ #
69
+
70
+ module Admin; end
71
+
72
+ class Admin::ApplicationController < ActionController::Base; end
73
+
74
+ class Admin::PostsController < Admin::ApplicationController
75
+ include Admini::Resources
76
+
77
+ private
78
+
79
+ def show_attributes
80
+ %i(title content)
81
+ end
82
+
83
+ def new_attributes
84
+ %i(title content)
85
+ end
86
+
87
+ def search_attributes
88
+ %i(title)
89
+ end
90
+
91
+ def can_delete?
92
+ false
93
+ end
94
+
95
+ def render_content(resource)
96
+ 'bar'
97
+ end
98
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Posts', type: :feature do
4
+ describe 'GET /admin/posts/:id' do
5
+ before do
6
+ Post.create(title: 'foo', content: 'foo')
7
+ visit admin_post_path(id: 1)
8
+ end
9
+
10
+ it 'has attributes set by #show_attributes' do
11
+ expect(page).to have_content('foo')
12
+ end
13
+
14
+ it 'has attributes overridden by #render_attribute' do
15
+ expect(page).to have_content('bar')
16
+ end
17
+ end
18
+
19
+ describe 'GET /admin/posts/new' do
20
+ it 'renders with form object set by #resource_object' do
21
+ visit new_admin_post_path
22
+ expect(page).to have_http_status(:ok)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ include Admini::ApplicationHelper
4
+
5
+ describe Admini::ApplicationHelper do
6
+ describe '#enable_action?' do
7
+ context 'enable all actions' do
8
+ let(:controller_path) { 'admin/posts' }
9
+
10
+ it 'all returns true' do
11
+ %i(index new create show edit update destroy).each do |action|
12
+ expect(enable_action?(action)).to be_truthy
13
+ end
14
+ end
15
+ end
16
+
17
+ context 'enable some actions' do
18
+ let(:controller_path) { 'admin/users' }
19
+
20
+ it 'returns true when passed enable action, otherwise false' do
21
+ %i(index show).each do |action|
22
+ expect(enable_action?(action)).to be_truthy
23
+ end
24
+
25
+ %i(new create edit update destroy).each do |action|
26
+ expect(enable_action?(action)).to be_falsy
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#search_options' do
33
+ let(:resource_name) { 'post' }
34
+ let(:search_attributes) { %i(title content) }
35
+
36
+ it 'returns option tags' do
37
+ expect(search_options).to eq "<option value=\"title\">Title</option>\n<option value=\"content\">Content</option>"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ require 'dummy/application'
2
+ require 'rspec/rails'
3
+ require 'rails-controller-testing'
4
+ require 'capybara/rspec'
5
+ require 'database_cleaner'
6
+
7
+ RSpec.configure do |config|
8
+ config.include Rails::Controller::Testing::TestProcess, type: :controller
9
+
10
+ config.around(:each) do |example|
11
+ DatabaseCleaner.cleaning do
12
+ example.run
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kami
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-01 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: actionpack
14
+ name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: jquery-rails
42
+ name: simple_form
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: simple_form
56
+ name: kaminari
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: kaminari
70
+ name: jquery-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,6 +80,104 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: actionpack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sqlite3
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rails-controller-testing
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: capybara
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: database_cleaner
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
83
181
  description: A minimal administration framework for Ruby on Rails application.
84
182
  email: hiroki.zenigami@gmail.com
85
183
  executables: []
@@ -87,6 +185,7 @@ extensions: []
87
185
  extra_rdoc_files: []
88
186
  files:
89
187
  - ".gitignore"
188
+ - ".travis.yml"
90
189
  - Gemfile
91
190
  - MIT-LICENSE
92
191
  - README.md
@@ -95,6 +194,7 @@ files:
95
194
  - app/assets/javascripts/admini/application.js
96
195
  - app/assets/stylesheets/admini/default.css
97
196
  - app/controllers/concerns/admini/resources.rb
197
+ - app/helpers/admini/application_helper.rb
98
198
  - app/views/admini/layouts/_header.html.erb
99
199
  - app/views/admini/layouts/_nav.html.erb
100
200
  - app/views/admini/layouts/_search.html.erb
@@ -111,9 +211,15 @@ files:
111
211
  - app/views/admini/shared/links/_show.html.erb
112
212
  - config/locales/admini.en.yml
113
213
  - config/locales/admini.ja.yml
214
+ - docs/screenshot.png
114
215
  - lib/admini.rb
115
216
  - lib/admini/engine.rb
116
217
  - lib/admini/version.rb
218
+ - spec/controllers/admin/posts_controller_spec.rb
219
+ - spec/dummy/application.rb
220
+ - spec/features/posts_spec.rb
221
+ - spec/helpers/admini/application_helper_spec.rb
222
+ - spec/spec_helper.rb
117
223
  homepage: https://github.com/kami-zh/admini
118
224
  licenses:
119
225
  - MIT