Permalink
Browse files

acl storage changed from xls to csv - for better diff

  • Loading branch information...
1 parent 1124f81 commit b6b9634ed9f3c6c6d55b85714983d9431a1f9cdb @unnitallman unnitallman committed Apr 23, 2012
View
@@ -2,5 +2,4 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in acts_as_authoritah.gemspec
gemspec
-gem 'spreadsheet'
@@ -13,8 +13,7 @@ module Matchers
require "acts_as_authoritah/identifier_parser"
require "acts_as_authoritah/errors.rb"
-require 'spreadsheet'
-Spreadsheet.client_encoding = 'UTF-8'
+require 'csv'
require "acts_as_authoritah/spreadsheets/access_rights_mapper"
require "acts_as_authoritah/spreadsheets/spreadsheet_wrapper"
@@ -5,7 +5,7 @@ def initialize(path)
@path = path
@files = []
@contexts = []
- Dir.glob(File.join(@path,"*.xls")).each{ |x|
+ Dir.glob(File.join(@path,"*.csv")).each{ |x|
@files << x
@contexts << File.split(x).last.split('.').first
}
@@ -1,8 +1,7 @@
class ActsAsAuthoritah::SpreadsheetReader
def initialize(path)
if File.exists?(path)
- @book = Spreadsheet.open path
- @sheet = @book.worksheets.first
+ @sheet = CSV.parse open(path).read.strip
else
@error = "File not found"
end
@@ -2,28 +2,28 @@
describe ActsAsAuthoritah::SpreadsheetReader do
it "should be able to open a spreadsheet give a valid path" do
- ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.xls").valid?.should eq true
+ ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.csv").valid?.should eq true
end
it "should be invalid if file not found" do
- ActsAsAuthoritah::SpreadsheetReader.new("spec/data/no_such_file.xls").valid?.should eq false
+ ActsAsAuthoritah::SpreadsheetReader.new("spec/data/no_such_file.csv").valid?.should eq false
end
it "should return all valid rows (skip first row and other empty rows)" do
- reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.xls")
+ reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.csv")
reader.valid_rows.count.should eq 2
end
it "should returns rows in the expected format" do
- reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.xls")
+ reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.csv")
reader.valid_rows.should eq [
["scope1::scope2", "Dummy", "edit", "test", "x", nil, "x"],
["scope3::scope4", "Another", "update", "test", nil, "x", "x"]
]
end
it "should return the header row" do
- reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.xls")
+ reader = ActsAsAuthoritah::SpreadsheetReader.new("spec/data/default.csv")
reader.header.should eq ["scope", "controller", "action", "description", "admin", "anonymous", "super_admin"]
end
end
@@ -2,11 +2,11 @@
describe ActsAsAuthoritah::SpreadsheetWrapper do
it "should be able to open a spreadsheet and convert to an array of AccessRules" do
- ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.xls").to_access_rules.first.class.should eq ActsAsAuthoritah::AccessRule
+ ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.csv").to_access_rules.first.class.should eq ActsAsAuthoritah::AccessRule
end
it "should load the spreadsheet to ACL correctly" do
- access_rules = ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.xls").to_access_rules
+ access_rules = ActsAsAuthoritah::SpreadsheetWrapper.new("spec/data/default.csv").to_access_rules
ActsAsAuthoritah::AccessControlList.new(access_rules).store.should eq({
"scope1::scope2::DummyController#edit"=>{"admin"=>true, "anonymous"=>false, "super_admin"=>true},
"scope3::scope4::AnotherController#update"=>{"admin"=>false, "anonymous"=>true, "super_admin"=>true}
View
@@ -0,0 +1 @@
+scope,controller,action,description,admin,anonymous,super_adminscope1::scope2,Dummy,edit,test,x,,xscope3::scope4,Another,update,test,x,x,x
View
@@ -0,0 +1 @@
+scope,controller,action,description,admin,anonymous,super_adminscope1::scope2,Dummy,edit,test,x,,xscope3::scope4,Another,update,test,,x,x
@@ -0,0 +1 @@
+scope,controller,action,description,admin,anonymous,super_admin,,,,,scope1::scope2,Dummy,edit,test,x,,x,,,,,scope3::scope4,Another,update,test,,x,x,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

0 comments on commit b6b9634

Please sign in to comment.