Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/binda/api_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def self.create_api_user
STDOUT.puts "What is the api user name? [api_user]"
username = STDIN.gets.strip
username = 'api_user' if username.blank?
ApiUser.create!( name: username )
new_user = ApiUser.create!( name: username )
puts "User \"#{username}\" successfully created."
::Binda::Structure.all.each do |structure|
new_user.structures << structure
end
new_user.save!
puts "User \"#{username}\" has now granted access to all existing structures."
end

private
Expand Down
9 changes: 9 additions & 0 deletions spec/models/binda/api_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ module Binda
users = ::Binda::ApiUser.all
expect(users.last.name).to eq('foo')
end

it "has a generator method to create users which are granted access to all existing structures" do
STDIN = StringIO.new("bar\n")
::Binda::ApiUser.create_api_user
num_of_structures = Structure.all.count
users = ::Binda::ApiUser.all
expect(users.last.name).to eq('bar')
expect(users.last.reload.structures.count).to eq(num_of_structures)
end
end
end