From 1d5f20953d6a4bf6de8dab1d915b4d252eb4a790 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 5 Aug 2011 14:12:09 +0200 Subject: cleanup code and improve test naming --- lib/trocla.rb | 6 +++--- spec/trocla_spec.rb | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/trocla.rb b/lib/trocla.rb index fe7696c..96f14d1 100644 --- a/lib/trocla.rb +++ b/lib/trocla.rb @@ -49,8 +49,8 @@ class Trocla end end - def set_password(key,format,password,delete_plain=false) - if ((format=format) == 'plain') && !delete_plain + def set_password(key,format,password) + if (format == 'plain') h = (cache[key] = { 'plain' => password }) else h = (cache[key] = cache.fetch(key,{}).merge({ format => password })) @@ -88,4 +88,4 @@ class Trocla YAML.load(File.read(File.expand_path(File.join(File.dirname(__FILE__),'trocla','default_config.yaml')))) end -end \ No newline at end of file +end diff --git a/spec/trocla_spec.rb b/spec/trocla_spec.rb index c6cb94c..fe95520 100644 --- a/spec/trocla_spec.rb +++ b/spec/trocla_spec.rb @@ -44,23 +44,23 @@ describe "Trocla" do describe "set_password" do it "should reset hashed passwords on a new plain password" do - @trocla.password('reset_test','mysql').should_not be_empty - @trocla.get_password('reset_test','mysql').should_not be_nil - (old_plain=@trocla.password('reset_test','mysql')).should_not be_empty + @trocla.password('set_test','mysql').should_not be_empty + @trocla.get_password('set_test','mysql').should_not be_nil + (old_plain=@trocla.password('set_test','mysql')).should_not be_empty - @trocla.set_password('reset_test','plain','foobar').should_not eql(old_plain) - @trocla.get_password('reset_test','mysql').should be_nil + @trocla.set_password('set_test','plain','foobar').should_not eql(old_plain) + @trocla.get_password('set_test','mysql').should be_nil end it "should otherwise only update the hash" do - (mysql = @trocla.password('reset_test2','mysql')).should_not be_empty - (md5crypt = @trocla.password('reset_test2','md5crypt')).should_not be_empty - (plain = @trocla.get_password('reset_test2','plain')).should_not be_empty + (mysql = @trocla.password('set_test2','mysql')).should_not be_empty + (md5crypt = @trocla.password('set_test2','md5crypt')).should_not be_empty + (plain = @trocla.get_password('set_test2','plain')).should_not be_empty - (new_mysql = @trocla.set_password('reset_test2','mysql','foo')).should_not eql(mysql) - @trocla.get_password('reset_test2','mysql').should eql(new_mysql) - @trocla.get_password('reset_test2','md5crypt').should eql(md5crypt) - @trocla.get_password('reset_test2','plain').should eql(plain) + (new_mysql = @trocla.set_password('set_test2','mysql','foo')).should_not eql(mysql) + @trocla.get_password('set_test2','mysql').should eql(new_mysql) + @trocla.get_password('set_test2','md5crypt').should eql(md5crypt) + @trocla.get_password('set_test2','plain').should eql(plain) end end -- cgit v1.2.3