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