admin_data 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -0
- data/app/controllers/admin_data/base_controller.rb +2 -7
- data/app/views/admin_data/main/edit.html.erb +1 -2
- data/app/views/admin_data/main/misc/_form.html.erb +9 -2
- data/app/views/admin_data/shared/_drop_down_klasses.html.erb +1 -1
- data/app/views/admin_data/shared/_powered_by.html.erb +3 -20
- data/lib/admin_data/helpers.rb +1 -1
- data/lib/admin_data/version.rb +1 -1
- data/lib/js/vendor/{code.jquery.com jquery-1.4.2.js → jquery-1.4.2.js} +0 -0
- metadata +9 -110
- data/README.textile +0 -21
- data/lib/js/vendor/jquery.lint.js +0 -604
- data/test/factories/article.rb +0 -9
- data/test/factories/car.rb +0 -4
- data/test/factories/city.rb +0 -4
- data/test/factories/comment.rb +0 -6
- data/test/factories/door.rb +0 -4
- data/test/factories/engine.rb +0 -4
- data/test/functional/base_controller_test.rb +0 -5
- data/test/functional/feed_controller_test.rb +0 -45
- data/test/functional/main_controller_authorization_test.rb +0 -91
- data/test/functional/main_controller_test.rb +0 -418
- data/test/functional/migration_controller_test.rb +0 -39
- data/test/functional/routes_test.rb +0 -59
- data/test/functional/search_controller_authorization_test.rb +0 -77
- data/test/functional/search_controller_test.rb +0 -811
- data/test/helper/view_helper_test.rb +0 -177
- data/test/misc_tests/date_validation_test.rb +0 -32
- data/test/misc_tests/settings_test.rb +0 -29
- data/test/misc_tests/util_test.rb +0 -83
- data/test/rails_root/Gemfile +0 -22
- data/test/rails_root/Gemfile.lock +0 -101
- data/test/rails_root/Rakefile +0 -7
- data/test/rails_root/app/controllers/application_controller.rb +0 -3
- data/test/rails_root/app/helpers/application_helper.rb +0 -2
- data/test/rails_root/app/models/article.rb +0 -25
- data/test/rails_root/app/models/city.rb +0 -15
- data/test/rails_root/app/models/comment.rb +0 -13
- data/test/rails_root/app/models/tech_magazine.rb +0 -2
- data/test/rails_root/app/models/vehicle/car.rb +0 -4
- data/test/rails_root/app/models/vehicle/door.rb +0 -3
- data/test/rails_root/app/models/vehicle/engine.rb +0 -3
- data/test/rails_root/app/views/layouts/application.html.erb +0 -14
- data/test/rails_root/config/application.rb +0 -42
- data/test/rails_root/config/boot.rb +0 -13
- data/test/rails_root/config/database.yml +0 -22
- data/test/rails_root/config/environment.rb +0 -5
- data/test/rails_root/config/environments/development.rb +0 -22
- data/test/rails_root/config/environments/production.rb +0 -49
- data/test/rails_root/config/environments/test.rb +0 -35
- data/test/rails_root/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_root/config/initializers/inflections.rb +0 -10
- data/test/rails_root/config/initializers/mime_types.rb +0 -5
- data/test/rails_root/config/initializers/secret_token.rb +0 -7
- data/test/rails_root/config/initializers/session_store.rb +0 -8
- data/test/rails_root/config/locales/en.yml +0 -5
- data/test/rails_root/config/routes.rb +0 -58
- data/test/rails_root/config.ru +0 -4
- data/test/rails_root/db/migrate/20090809061114_create_tables.rb +0 -70
- data/test/rails_root/db/schema.rb +0 -74
- data/test/rails_root/db/seeds.rb +0 -7
- data/test/rails_root/db/test.sqlite3 +0 -0
- data/test/rails_root/script/rails +0 -6
- data/test/rails_root/test/performance/browsing_test.rb +0 -0
- data/test/rails_root/test/test_helper.rb +0 -13
- data/test/support/assertions.rb +0 -20
- data/test/test_helper.rb +0 -76
data/test/factories/city.rb
DELETED
data/test/factories/comment.rb
DELETED
data/test/factories/door.rb
DELETED
data/test/factories/engine.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
f = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views')
|
4
|
-
AdminData::FeedController.prepend_view_path(f)
|
5
|
-
|
6
|
-
require 'nokogiri'
|
7
|
-
|
8
|
-
class AdminData::FeedControllerTest < ActionController::TestCase
|
9
|
-
|
10
|
-
context 'authorization' do
|
11
|
-
context 'failure' do
|
12
|
-
setup do
|
13
|
-
AdminData::Config.set = { :feed_authentication_user_id => 'hello', :feed_authentication_password => 'world' }
|
14
|
-
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('bad_userid', 'bad_password')
|
15
|
-
get :index, :format => :rss, :klasss => 'article',
|
16
|
-
'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials('bad_user', 'bad_password')
|
17
|
-
end
|
18
|
-
should_respond_with(401)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
context 'GET index' do
|
24
|
-
setup do
|
25
|
-
AdminData::Config.set = { :feed_authentication_user_id => 'hello', :feed_authentication_password => 'world' }
|
26
|
-
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('hello', 'world')
|
27
|
-
Article.delete_all
|
28
|
-
@article = Factory(:article)
|
29
|
-
get :index, :format => :rss, :klasss => 'article'
|
30
|
-
@feed = Nokogiri::XML(@response.body)
|
31
|
-
end
|
32
|
-
should_respond_with :success
|
33
|
-
should 'have RSS feed 2.0' do
|
34
|
-
assert_equal '2.0', @feed.at('rss')['version']
|
35
|
-
end
|
36
|
-
should 'have title' do
|
37
|
-
assert_equal "Feeds from admin_data Article id: #{@article.id}", @feed.css('channel title').text
|
38
|
-
end
|
39
|
-
should 'have guid' do
|
40
|
-
guid = @feed.css('channel item guid').text
|
41
|
-
assert Regexp.new("/admin_data/klass/Article/#{@article.id}-").match(guid)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
f = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views')
|
4
|
-
AdminData::MainController.prepend_view_path(f)
|
5
|
-
|
6
|
-
class AdminData::MainControllerAuthorizationTest < ActionController::TestCase
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@controller = AdminData::MainController.new
|
10
|
-
@request = ActionController::TestRequest.new
|
11
|
-
@response = ActionController::TestResponse.new
|
12
|
-
@article = Factory(:article)
|
13
|
-
grant_read_only_access
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'is not allowed to view' do
|
17
|
-
setup do
|
18
|
-
revoke_read_only_access
|
19
|
-
get :table_structure, {:klass => Article.name.underscore}
|
20
|
-
end
|
21
|
-
should_respond_with(401)
|
22
|
-
should 'have text index' do
|
23
|
-
assert_tag(:content => 'not authorized')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'is allowed to view klass' do
|
28
|
-
context 'negative case' do
|
29
|
-
setup do
|
30
|
-
_proc = lambda {|controller| controller.instance_variable_get('@klass').name != 'Article' }
|
31
|
-
AdminData::Config.set = { :is_allowed_to_view_klass => _proc }
|
32
|
-
get :show, {:id => @article.id, :klass => Article.name.underscore }
|
33
|
-
end
|
34
|
-
should_respond_with(401)
|
35
|
-
should 'have text index' do
|
36
|
-
assert_tag(:content => 'not authorized')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
context 'positive case' do
|
40
|
-
setup do
|
41
|
-
_proc = lambda {|controller| controller.instance_variable_get('@klass').name == 'Article' }
|
42
|
-
AdminData::Config.set = { :is_allowed_to_view_klass => _proc }
|
43
|
-
get :show, {:id => @article.id, :klass => Article.name.underscore }
|
44
|
-
end
|
45
|
-
should_respond_with :success
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'is allowed to update' do
|
50
|
-
context 'for edit' do
|
51
|
-
setup do
|
52
|
-
AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
|
53
|
-
get :edit, {:id => @article.id, :klass => @article.class.name, :attr => 'title', :data => 'Hello World' }
|
54
|
-
end
|
55
|
-
should_respond_with(401)
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'for destroy' do
|
59
|
-
setup do
|
60
|
-
AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
|
61
|
-
delete :destroy, {:id => @article.id, :klass => @article.class.name.underscore}
|
62
|
-
end
|
63
|
-
should_respond_with(401)
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'for delete' do
|
67
|
-
setup do
|
68
|
-
AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
|
69
|
-
delete :del, {:id => @article.id, :klass => @article.class.name.underscore }
|
70
|
-
end
|
71
|
-
should_respond_with(401)
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'for update' do
|
75
|
-
setup do
|
76
|
-
AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
|
77
|
-
post :update, { :klass => Article.name.underscore, :id => @article, :article => {:title => 'new title'}}
|
78
|
-
end
|
79
|
-
should_respond_with(401)
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'for create' do
|
83
|
-
setup do
|
84
|
-
AdminData::Config.set = { :is_allowed_to_update => lambda {|controller| false } }
|
85
|
-
post :create, { :klass => Article.name.underscore, 'article' => {:title => 'hello', :body => 'hello world'}}
|
86
|
-
end
|
87
|
-
should_respond_with(401)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
@@ -1,418 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
f = File.join(File.dirname(__FILE__), '..', '..', 'app', 'views')
|
4
|
-
AdminData::MainController.prepend_view_path(f)
|
5
|
-
|
6
|
-
class AdminData::MainControllerTest < ActionController::TestCase
|
7
|
-
|
8
|
-
def setup
|
9
|
-
@controller = AdminData::MainController.new
|
10
|
-
@request = ActionController::TestRequest.new
|
11
|
-
@response = ActionController::TestResponse.new
|
12
|
-
@article = Factory(:article)
|
13
|
-
@car = Factory(:car, :year => 2000, :brand => 'bmw')
|
14
|
-
grant_read_only_access
|
15
|
-
grant_update_access
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'get table_structure' do
|
19
|
-
setup do
|
20
|
-
get :table_structure, {:klass => Article.name.underscore}
|
21
|
-
end
|
22
|
-
should_respond_with :success
|
23
|
-
should 'have text index' do
|
24
|
-
assert_tag(:content => 'Index')
|
25
|
-
end
|
26
|
-
should 'have table name' do
|
27
|
-
assert_tag(:tag => 'h1', :content => "Table name : articles", :attributes => {:class => 'table_name'})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'get all_models' do
|
32
|
-
setup do
|
33
|
-
get :all_models
|
34
|
-
end
|
35
|
-
should_respond_with :success
|
36
|
-
should_assign_to :klasses
|
37
|
-
should 'have xx number of models' do
|
38
|
-
assert_equal 7, assigns(:klasses).size
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'get show for article which belongs to tech_magazine' do
|
43
|
-
setup do
|
44
|
-
@article.magazine = TechMagazine.create
|
45
|
-
@article.save
|
46
|
-
get :show, {:id => @article, :klass => @article.class.name.underscore }
|
47
|
-
end
|
48
|
-
should_respond_with :success
|
49
|
-
should 'have belongs to association with magazine' do
|
50
|
-
assert @article.magazine
|
51
|
-
end
|
52
|
-
should 'have association link for comments' do
|
53
|
-
s2 = ERB::Util.html_escape('&')
|
54
|
-
url = "/admin_data/klass/tech_magazine/#{@article.magazine.id}"
|
55
|
-
assert_tag(:tag => 'a', :attributes => {:href => url})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'get show for article which has many comments' do
|
60
|
-
setup do
|
61
|
-
@comment1 = Factory(:comment, :article => @article)
|
62
|
-
@comment2 = Factory(:comment, :article => @article)
|
63
|
-
get :show, {:id => @article.id, :klass => @article.class.name.underscore }
|
64
|
-
end
|
65
|
-
should_respond_with :success
|
66
|
-
should 'have association link for comments' do
|
67
|
-
s2 = ERB::Util.html_escape('&')
|
68
|
-
url = "/admin_data/quick_search/comment?children=comments#{s2}model_id=#{@article.id}#{s2}base=article"
|
69
|
-
assert_tag(:tag => 'a', :attributes => {:href => url})
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context 'get show for car' do
|
74
|
-
setup do
|
75
|
-
@engine = Factory(:engine, :car => @car, :cylinders => 4)
|
76
|
-
get :show, {:id => @car.id, :klass => @car.class.name.underscore }
|
77
|
-
end
|
78
|
-
#should_respond_with :success
|
79
|
-
#should 'have one association link for engine' do
|
80
|
-
#s2 = ERB::Util.html_escape('&')
|
81
|
-
#url = "/admin_data/klass/engine/#{@engine.id}"
|
82
|
-
#assert_tag(:tag => 'a', :content => /engine/, :attributes => {:href => url})
|
83
|
-
#end
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'get show for city' do
|
87
|
-
setup do
|
88
|
-
AdminData::Config.set = { :find_conditions => { 'City' => lambda { |params| {:conditions => ["permanent_name =?", params[:id]] } } } }
|
89
|
-
@city = Factory(:city, :name => 'New Delhi')
|
90
|
-
get :show, {:id => 'new-delhi', :klass => @city.class.name.underscore }
|
91
|
-
end
|
92
|
-
should_respond_with :success
|
93
|
-
end
|
94
|
-
|
95
|
-
context 'get show for comment which belongs to another class' do
|
96
|
-
setup do
|
97
|
-
@comment = Factory(:comment, :article => @article)
|
98
|
-
get :show, {:id => @comment.id, :klass => @comment.class.name.underscore }
|
99
|
-
end
|
100
|
-
should_respond_with :success
|
101
|
-
should 'have belongs_to message' do
|
102
|
-
assert_tag( :tag => 'p',
|
103
|
-
:attributes => {:class => 'belongs_to'},
|
104
|
-
:descendant => {:tag => 'a', :child => /article/})
|
105
|
-
end
|
106
|
-
should 'have link to belongs_to association' do
|
107
|
-
s2 = ERB::Util.html_escape('&')
|
108
|
-
url = "/admin_data/klass/article/#{@article.to_param}"
|
109
|
-
assert_tag(:tag => 'a', :attributes => {:href => url})
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context 'get show for door which belongs to another class' do
|
114
|
-
setup do
|
115
|
-
@door = Factory(:door, :color => 'blue', :car_id => @car.id)
|
116
|
-
get :show, {:id => @door.id, :klass => @door.class.name.underscore }
|
117
|
-
end
|
118
|
-
#should_respond_with :success
|
119
|
-
#should 'have belongs_to message' do
|
120
|
-
#assert_tag( :tag => 'p',
|
121
|
-
#:attributes => {:class => 'belongs_to'},
|
122
|
-
#:descendant => {:tag => 'a', :child => /car/})
|
123
|
-
#end
|
124
|
-
end
|
125
|
-
|
126
|
-
context 'destroy an article' do
|
127
|
-
setup do
|
128
|
-
grant_update_access
|
129
|
-
@comment = Factory(:comment, :article => @article)
|
130
|
-
delete :destroy, {:id => @article.id, :klass => @article.class.name.underscore}
|
131
|
-
end
|
132
|
-
should_respond_with :redirect
|
133
|
-
should_change('article count', :by => -1) {Article.count}
|
134
|
-
# a comment is being created in setup which should be deleted because of destroy
|
135
|
-
should_not_change('comment count') { Comment.count }
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'destroy a car' do
|
139
|
-
setup do
|
140
|
-
grant_update_access
|
141
|
-
@door = Factory(:door, :color => 'blue', :car => @car)
|
142
|
-
delete :destroy, {:id => @car.id, :klass => @car.class.name.underscore}
|
143
|
-
end
|
144
|
-
#should_respond_with :redirect
|
145
|
-
#should_change('car count', :by => -1) {Vehicle::Car.count}
|
146
|
-
## a comment is being created in setup which should be deleted because of destroy
|
147
|
-
#should_not_change('door count') { Vehicle::Door.count }
|
148
|
-
end
|
149
|
-
|
150
|
-
context 'delete an article' do
|
151
|
-
setup do
|
152
|
-
grant_update_access
|
153
|
-
@comment = Factory(:comment, :article => @article)
|
154
|
-
delete :del, {:id => @article.id, :klass => @article.class.name.underscore }
|
155
|
-
end
|
156
|
-
should_respond_with :redirect
|
157
|
-
should_change('article count', :by => -1) {Article.count}
|
158
|
-
should_change('comment count', :by => 1) {Comment.count}
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'delete a car' do
|
162
|
-
setup do
|
163
|
-
grant_update_access
|
164
|
-
@door = Factory(:door, :color => 'blue', :car => @car)
|
165
|
-
delete :del, {:id => @car.id, :klass => @car.class.name.underscore }
|
166
|
-
end
|
167
|
-
#should_respond_with :redirect
|
168
|
-
#should_change('car count', :by => -1) {Vehicle::Car.count}
|
169
|
-
#should_change('door count since del does not call callbacks', :by => 1) do
|
170
|
-
#Vehicle::Door.count
|
171
|
-
#end
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'get edit article with attr' do
|
175
|
-
setup do
|
176
|
-
get :edit, {:id => @article.id, :klass => @article.class.name, :attr => 'title', :data => 'Hello World' }
|
177
|
-
end
|
178
|
-
should 'have input field for title' do
|
179
|
-
assert_select('#article_title')
|
180
|
-
end
|
181
|
-
should 'not have input field for body' do
|
182
|
-
assert_select('#article_body', false)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'get edit article' do
|
187
|
-
context 'with ignore column limit' do
|
188
|
-
setup do
|
189
|
-
AdminData::Config.set = ({:ignore_column_limit => true})
|
190
|
-
get :edit, {:id => @article.id, :klass => @article.class.name }
|
191
|
-
end
|
192
|
-
teardown do
|
193
|
-
AdminData::Config.set = ({:ignore_column_limit => false})
|
194
|
-
end
|
195
|
-
|
196
|
-
should 'have size 60 for title and maxlenght 255' do
|
197
|
-
assert_tag(:tag => 'input', :attributes => {:id=> 'article_title', :size => '60', :maxlength => '255'})
|
198
|
-
end
|
199
|
-
|
200
|
-
should 'have size 60 for status and maxlenght 200' do
|
201
|
-
assert_tag(:tag => 'input', :attributes => {:id=> 'article_status', :size => '60', :maxlength => '255'})
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
context 'with enforced column limit' do
|
206
|
-
|
207
|
-
setup do
|
208
|
-
get :edit, {:id => @article.id, :klass => @article.class.name }
|
209
|
-
end
|
210
|
-
should_respond_with :success
|
211
|
-
|
212
|
-
should "not have input for primary key" do
|
213
|
-
assert_select 'form' do
|
214
|
-
assert_select "input[name='comment[id]']", false
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
should "have dropdowns for published_at datetime column" do
|
219
|
-
assert_select 'form' do
|
220
|
-
assert_select "select[name='article[published_at(1i)]']"
|
221
|
-
assert_select "select[name='article[published_at(2i)]']"
|
222
|
-
assert_select "select[name='article[published_at(3i)]']"
|
223
|
-
assert_select "select[name='article[published_at(4i)]']"
|
224
|
-
assert_select "select[name='article[published_at(5i)]']"
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
should 'have input field for title' do
|
229
|
-
assert_select('#article_title')
|
230
|
-
end
|
231
|
-
|
232
|
-
should 'have size 60 for title and maxlenght 200' do
|
233
|
-
assert_tag(:tag => 'input', :attributes => {:id=> 'article_title', :size => '60', :maxlength => '200'})
|
234
|
-
end
|
235
|
-
|
236
|
-
should 'have size 60 for status and maxlenght 200' do
|
237
|
-
assert_tag(:tag => 'input', :attributes => {:id=> 'article_status', :size => '50', :maxlength => '50'})
|
238
|
-
end
|
239
|
-
|
240
|
-
should 'have input field for body' do
|
241
|
-
assert_select('#article_body')
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
context 'get edit comment' do
|
248
|
-
context 'without drop down for associations' do
|
249
|
-
setup do
|
250
|
-
AdminData::Config.set = ({:drop_down_for_associations => false})
|
251
|
-
@comment = Factory(:comment, :article => @article)
|
252
|
-
get :edit, {:id => @comment.id, :klass => @comment.class.name.underscore }
|
253
|
-
end
|
254
|
-
teardown do
|
255
|
-
AdminData::Config.set = ({:drop_down_for_associations => true})
|
256
|
-
end
|
257
|
-
|
258
|
-
should_respond_with :success
|
259
|
-
|
260
|
-
should "have input text field for belongs_to article" do
|
261
|
-
assert_select 'form' do
|
262
|
-
assert_tag(:tag => 'input', :attributes => {:id => 'comment_article_id', :name => 'comment[article_id]'})
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
context 'with drop down for associations' do
|
267
|
-
setup do
|
268
|
-
@comment = Factory(:comment, :article => @article)
|
269
|
-
get :edit, {:id => @comment.id, :klass => @comment.class.name.underscore }
|
270
|
-
end
|
271
|
-
|
272
|
-
should_respond_with :success
|
273
|
-
|
274
|
-
should "have dropdowns for belongs_to article" do
|
275
|
-
assert_select 'form' do
|
276
|
-
assert_select "select[name='comment[article_id]']"
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
|
283
|
-
context 'get edit car' do
|
284
|
-
setup do
|
285
|
-
get :edit, {:id => @car.id, :klass => @car.class.name.underscore }
|
286
|
-
end
|
287
|
-
#should_respond_with :success
|
288
|
-
end
|
289
|
-
|
290
|
-
context 'get new article' do
|
291
|
-
setup do
|
292
|
-
get :new, {:klass => Article.name.underscore }
|
293
|
-
end
|
294
|
-
should_respond_with :success
|
295
|
-
end
|
296
|
-
|
297
|
-
context 'get new car' do
|
298
|
-
setup do
|
299
|
-
get :new, {:klass => Vehicle::Car.name.underscore}
|
300
|
-
end
|
301
|
-
#should_respond_with :success
|
302
|
-
end
|
303
|
-
|
304
|
-
context 'update article successful' do
|
305
|
-
setup do
|
306
|
-
grant_update_access
|
307
|
-
post :update, { :klass => Article.name.underscore, :id => @article, :article => {:title => 'new title'}}
|
308
|
-
end
|
309
|
-
should_respond_with :redirect
|
310
|
-
should_redirect_to('show page') { admin_data_on_k_path( :id => Article.last, :klass => Article.name.underscore) }
|
311
|
-
should_set_the_flash_to /Record was updated/
|
312
|
-
should_not_change('article count') { Article.count }
|
313
|
-
end
|
314
|
-
|
315
|
-
context 'update car successful' do
|
316
|
-
setup do
|
317
|
-
grant_update_access
|
318
|
-
post :update, { :klass => Vehicle::Car.name.underscore, :id => @car.id, 'vehicle/car' => {:brand => 'honda'}}
|
319
|
-
end
|
320
|
-
#should_respond_with :redirect
|
321
|
-
#should_redirect_to('show page') { admin_data_on_k_path(:id => Vehicle::Car.last.id,
|
322
|
-
#:klass => @car.class.name.underscore) }
|
323
|
-
#should_set_the_flash_to /Record was updated/
|
324
|
-
#should_not_change('car count') { Vehicle::Car.count }
|
325
|
-
end
|
326
|
-
|
327
|
-
context 'update failure' do
|
328
|
-
setup do
|
329
|
-
grant_update_access
|
330
|
-
post :update, { :klass => 'article', :id => @article.id, :article => {:body => ''}}
|
331
|
-
end
|
332
|
-
should_respond_with :success
|
333
|
-
should_not_set_the_flash
|
334
|
-
should_not_change('article count') { Article.count }
|
335
|
-
should 'contain the error message' do
|
336
|
-
assert_tag(:content => "Body can't be blank")
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
context 'create article successful' do
|
341
|
-
setup do
|
342
|
-
grant_update_access
|
343
|
-
post :create, { :klass => Article.name.underscore, 'article' => {:title => 'hello', :body => 'hello world'}}
|
344
|
-
end
|
345
|
-
should_respond_with :redirect
|
346
|
-
should_redirect_to('show page') { admin_data_on_k_path(:id => Article.last,
|
347
|
-
:klass => @article.class.name.underscore) }
|
348
|
-
should_set_the_flash_to /Record was created/
|
349
|
-
should_change('article count', :by => 1) { Article.count }
|
350
|
-
end
|
351
|
-
|
352
|
-
context 'create car successful' do
|
353
|
-
setup do
|
354
|
-
grant_update_access
|
355
|
-
post :create, { :klass => Vehicle::Car.name.underscore, 'vehicle/car' => {:brand => 'hello'}}
|
356
|
-
end
|
357
|
-
#should_respond_with :redirect
|
358
|
-
#should_redirect_to('show page') { admin_data_on_k_path(:id => Vehicle::Car.last.id,
|
359
|
-
#:klass => @car.class.name.underscore) }
|
360
|
-
#should_set_the_flash_to /Record was created/
|
361
|
-
#should_change('vehicle count', :by => 1) { Vehicle::Car.count }
|
362
|
-
end
|
363
|
-
|
364
|
-
context 'create failure' do
|
365
|
-
setup do
|
366
|
-
grant_update_access
|
367
|
-
post :create, { :klass => Article.name.underscore, :article => {:body => '', :title => 'hello'}}
|
368
|
-
end
|
369
|
-
should_respond_with :success
|
370
|
-
should_not_set_the_flash
|
371
|
-
should_not_change('article count') { Article.count }
|
372
|
-
should 'contain the error message' do
|
373
|
-
assert_tag(:content => "Body can't be blank")
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
context 'filter get_model_and_verify_if failure case' do
|
378
|
-
setup do
|
379
|
-
get :show, {:id => 999999999999994533, :klass => Article.name.underscore }
|
380
|
-
end
|
381
|
-
should_respond_with :not_found
|
382
|
-
should 'contain the error message' do
|
383
|
-
assert_tag(:tag => 'h2', :content => "Article not found: 999999999999994533")
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
|
-
context 'filter is_allowed_to_view failure case' do
|
388
|
-
setup do
|
389
|
-
revoke_read_only_access
|
390
|
-
get :show, {:id => @article.id, :klass => Article.name.underscore }
|
391
|
-
end
|
392
|
-
should_respond_with :unauthorized
|
393
|
-
should 'contain the message' do
|
394
|
-
assert_tag(:tag => 'h2', :content => 'not authorized')
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
context 'fine grained access control' do
|
399
|
-
teardown do
|
400
|
-
AdminData::Config.initialize_defaults
|
401
|
-
end
|
402
|
-
context 'allows view security check to access klass' do
|
403
|
-
setup do
|
404
|
-
AdminData::Config.set = { :is_allowed_to_view_model => Proc.new { |controller| assert_equal(Article, controller.klass); true } }
|
405
|
-
get :show, {:id => @article.id, :klass => Article.name.underscore }
|
406
|
-
end
|
407
|
-
#should_respond_with :success
|
408
|
-
end
|
409
|
-
context 'allows update security check to access klass' do
|
410
|
-
setup do
|
411
|
-
AdminData::Config.set = { :is_allowed_to_update => Proc.new { |controller| assert_equal(Article, controller.klass); true } }
|
412
|
-
get :edit, {:id => @article.id, :klass => Article.name.underscore }
|
413
|
-
end
|
414
|
-
should_respond_with :success
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
pwd = File.dirname(__FILE__)
|
2
|
-
require File.join(pwd, '..', 'test_helper')
|
3
|
-
|
4
|
-
f = File.join(pwd, '..', '..', 'app', 'views')
|
5
|
-
AdminData::MainController.prepend_view_path(f)
|
6
|
-
AdminData::MigrationController.prepend_view_path(f)
|
7
|
-
|
8
|
-
class AdminData::MigrationControllerTest < ActionController::TestCase
|
9
|
-
|
10
|
-
def setup
|
11
|
-
@controller = AdminData::MigrationController.new
|
12
|
-
@request = ActionController::TestRequest.new
|
13
|
-
@response = ActionController::TestResponse.new
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'authorization check' do
|
17
|
-
setup do
|
18
|
-
revoke_read_only_access
|
19
|
-
get :index
|
20
|
-
end
|
21
|
-
should_respond_with(401)
|
22
|
-
should 'have text index' do
|
23
|
-
assert_tag(:content => 'not authorized')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'GET index' do
|
28
|
-
setup do
|
29
|
-
grant_read_only_access
|
30
|
-
get :index
|
31
|
-
end
|
32
|
-
should_respond_with :success
|
33
|
-
should_assign_to :data
|
34
|
-
should 'contain title' do
|
35
|
-
assert_tag(:tag => 'h2', :content => 'Migration Information from schema_migrations table')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class AdminData::MainControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
should route(:get, '/admin_data/quick_search/article').to(:controller => 'admin_data/search',
|
6
|
-
:action => :quick_search,
|
7
|
-
:klass => 'article')
|
8
|
-
|
9
|
-
should route(:get, '/admin_data/advance_search/article').to(:controller => 'admin_data/search',
|
10
|
-
:action => :advance_search,
|
11
|
-
:klass => 'article')
|
12
|
-
|
13
|
-
should route(:get, '/admin_data/migration').to(:controller => 'admin_data/migration',
|
14
|
-
:action => :index)
|
15
|
-
|
16
|
-
should route(:get, '/admin_data').to(:controller => 'admin_data/main',
|
17
|
-
:action => :all_models)
|
18
|
-
|
19
|
-
should route(:get, '/admin_data').to(:controller => 'admin_data/main',
|
20
|
-
:action => :all_models)
|
21
|
-
|
22
|
-
should route(:get, '/admin_data/klass/article/1').to(:controller => 'admin_data/main',
|
23
|
-
:action => :show,
|
24
|
-
:klass => 'article',
|
25
|
-
:id => 1)
|
26
|
-
|
27
|
-
should route(:delete, '/admin_data/klass/article/1').to(:controller => 'admin_data/main',
|
28
|
-
:action => :destroy,
|
29
|
-
:klass => 'article',
|
30
|
-
:id => 1)
|
31
|
-
|
32
|
-
should route(:delete, '/admin_data/klass/article/1/del').to(:controller => 'admin_data/main',
|
33
|
-
:action => :del,
|
34
|
-
:klass => 'article',
|
35
|
-
:id => 1)
|
36
|
-
|
37
|
-
should route(:get, '/admin_data/klass/article/1/edit').to(:controller => 'admin_data/main',
|
38
|
-
:action => :edit,
|
39
|
-
:klass => 'article',
|
40
|
-
:id => 1)
|
41
|
-
|
42
|
-
should route(:put, '/admin_data/klass/article/1').to(:controller => 'admin_data/main',
|
43
|
-
:action => :update,
|
44
|
-
:klass => 'article',
|
45
|
-
:id => 1)
|
46
|
-
|
47
|
-
should route(:get, '/admin_data/klass/article/new').to(:controller => 'admin_data/main',
|
48
|
-
:action => :new,
|
49
|
-
:klass => 'article')
|
50
|
-
|
51
|
-
should route(:post, '/admin_data/klass/article').to(:controller => 'admin_data/main',
|
52
|
-
:action => :create,
|
53
|
-
:klass => 'article')
|
54
|
-
|
55
|
-
should route(:get, '/admin_data/klass/article/table_structure').to(:controller => 'admin_data/main',
|
56
|
-
:action => :table_structure,
|
57
|
-
:klass => 'article')
|
58
|
-
|
59
|
-
end
|