Doctrine2文档说软删除行为应该更好地实现为状态模式但不提供任何该实现的示例.
如何使用状态模式实现软删除行为?
参考jsfiddle
var obj = {
set bla(k) {
console.log(k);
}
};
Run Code Online (Sandbox Code Playgroud)
JSHint将此标记为"setter is without getter".我确信有一种方法可以关闭它,但为什么这是一个错误呢?我所见过的所有JSHint旗帜都有一个合理的解释.我无法想出为什么这是一件坏事.
我有以下模型,我想用RSpec测试:
class Language < ActiveRecord::Base
has_and_belongs_to_many :dvds
validates :title, presence: true, uniqueness: { case_sensitive: false }
end
Run Code Online (Sandbox Code Playgroud)
language_spec.rb
describe Language do
describe 'title validation' do
context 'title is present' do
before(:each) do
@lang = Language.new(title: 'English')
end
it 'is valid with present title' do
expect(@lang).to have_exactly(0).errors_on(:title)
end
end
context 'title is not present' do
before(:each) do
@lang = Language.create
end
it 'has an error on title attribute' do
expect(@lang).to have_exactly(1).errors_on(:title)
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
不幸的是我遇到了测试失败:
失败:
1)语言标题验证标题存在对当前标题有效失败/错误:期望(@lang).to have_exactly(0).errors_on(:title)NoMethodError:未定义的方法
errors_on' for …
我想知道是否有人知道在没有任何上述先决条件的情况下是否可以使用FactoryGirl.
我想用它来为移动和网络推动UI自动化测试时生成即时测试数据,甚至可能是API.
我知道我可以创建一些自定义帮助器类/方法并使用getter和setter等,但我认为使用这个很棒的小宝石会很好.
我搜索得相当广泛,并试图建立一个基本的RSpec项目(我也试过Cucumber),但无济于事.我似乎仍然需要使用相关登录实例化类以便使用它.
FactoryGirl.define do
factory :user do
firstname { Faker::Name.first_name }
lastname { Faker::Name.last_name }
age { 1 + rand(100) }
end
end
Run Code Online (Sandbox Code Playgroud)
然后,如果我尝试在RSpec文件中调用它...
describe...
it...
user = build_stubbed(:user)
end
end
Run Code Online (Sandbox Code Playgroud)
我也阅读了文档并尝试了所有其他变体,我只是继续...
Failure/Error: user = build_stubbed(:user)
NameError:
uninitialized constant User
Run Code Online (Sandbox Code Playgroud)
这表明我需要一个名为User的类,包含所有逻辑.
我正在使用 RSpec/Capybara 进行 Rails 应用程序测试,我需要检查视图中的一个元素是否出现且仅出现一次。
例如,在下面的代码中,我需要确保它只task.title在页面中出现一次。如图所示,我可以检查它是否存在,但我找不到如何检查它是否只出现一次。
task = FactoryGirl.create(:task)
login_as(task.user, :scope => :user)
visit tasks_index_url
expect(page).to have_content task.title
Run Code Online (Sandbox Code Playgroud) rspec ruby-on-rails capybara capybara-webkit ruby-on-rails-4
我目前有4种类型的用户,我们预测将来至少还有3种.现在它们是:
在不久的将来,我将不得不让两位员工同时成为客户.我也有支持中心和记者.
创建.创建.创建.我并不担心访问控制,权限等...我现在的代码可以在这方面做奇迹.我的问题只是关于创造.似乎抽象工厂对我来说可能是一个,但事实是所有那些"抽象教程"教学设计模式使用书籍和汽车只是没有帮助我把它带到我的情况.要么我的设计模式错误,要么我不理解它.
在UserFactory类中,我们可以看到问题的根源:abstract public function signUp();.这是不好的做法,甚至导致PHP 5.4+上的严格标准错误不尊重方法签名.在Java中,我会有方法重载来解决这个问题.在PHP中,方法重载的工作方式不同,不允许我以这种方式工作.
<?php
abstract class UserFactory {
const ADMIN = 'AdminRecord';
const MANAGER = 'ManagerRecord';
const SALESMAN = 'SalesmanRecord';
const CUSTOMER = 'CustomerRecord';
public static function manufacture($type) {
return new $type;
}
protected $accountController;
protected $emailController;
protected $toolMailer;
function __construct() {
$this->accountController = new AccountController();
$this->emailController = new EmailController();
$this->toolMailer = new ToolMailer();
}
abstract public function signUp();
}
Run Code Online (Sandbox Code Playgroud)
这是我的第一个用例:创建一个新的管理员.
class AdminRecord extends UserFactory { …Run Code Online (Sandbox Code Playgroud) 有没有办法阻止图像上传到docker hub与现有图像相同的标签?我们的用例如下.
我们使用docker-compose文件部署到生产环境,并将图像标记作为版本号.为了支持回滚到先前的环境和幂等部署,必须使某个标记的泊坞窗图像始终引用相同的图像.
但是,docker hub允许使用与现有图像相同的标签上载图像(它们覆盖旧图像).这完全打破了对图像进行版本控制的想法.
我们目前有一些解决方法,包括我们的构建脚本拉动图像的所有版本,并查看标签以检查覆盖不会发生等等,但感觉必须有更好的方法.
如果docker hub不支持这个,有没有办法在没有docker hub的情况下进行docker部署?
在部署到Heroku时,我收到"错误:找不到模块"错误.
// package.json
{
"name": "AppName",
"version": "1.0.0",
"description": "== README",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "somerepo.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"browserify": "^11.0.1",
"browserify-incremental": "^3.0.1",
"object-assign": "^3.0.0",
"react": "^0.13.3",
"react-image-gallery": "^0.4.1",
"reactify": "^1.1.1",
"superagent": "^1.3.0"
},
"devDependencies": {
"es6-promise": "^2.3.0"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我运行"git push heroku master"时的日志
remote: -----> Build succeeded!
remote: ??? browserify@11.0.1
remote: ??? browserify-incremental@3.0.1
remote: ??? object-assign@3.0.0
remote: ??? react@0.13.3
remote: …Run Code Online (Sandbox Code Playgroud) 我试图遵循接口隔离和单一职责原则,但是我对如何将它们整合在一起感到困惑。
在这里,我有一个示例,其中有一些接口,我已将其拆分为更小、更直接的接口:
public interface IDataRead
{
TModel Get<TModel>(int id);
}
public interface IDataWrite
{
void Save<TModel>(TModel model);
}
public interface IDataDelete
{
void Delete<TModel>(int id);
void Delete<TModel>(TModel model);
}
Run Code Online (Sandbox Code Playgroud)
我稍微简化了它(有一些where条款妨碍了可读性)。
目前我正在使用SQLite ,但是,这种模式的美妙之处在于,如果我选择不同的数据存储方法(例如Azure),它有望让我有机会更好地适应变化。
现在,我对每个接口都有一个实现,下面是每个接口的简化示例:
public class DataDeleterSQLite : IDataDelete
{
SQLiteConnection _Connection;
public DataDeleterSQLite(SQLiteConnection connection) { ... }
public void Delete<TModel>(TModel model) { ... }
}
...
public class DataReaderSQLite : IDataRead
{
SQLiteConnection _Connection;
public DataReaderSQLite(SQLiteConnection connection) { ... }
public …Run Code Online (Sandbox Code Playgroud) c# interface single-responsibility-principle solid-principles interface-segregation-principle
我已经实现了一个网络钩子。调用者提供共享秘密。它们连接请求 URL 和正文,使用密钥对其进行签名,并在标头中提供签名。为了验证签名,我需要重复该过程并将我获得的签名与调用者获得的签名进行比较。
我正在使用 Django REST 框架。我正在检查自定义中的签名Authentication。框架以请求作为参数来调用Authentication的方法。authenticate我可以从 获取请求正文request.stream.read()。但是,这会消耗流,从而阻止框架为我解析它:当框架调用视图时,请求没有data像通常那样的属性。
request.stream不允许我这样做seek(0)。该请求不允许我用倒带流(例如StringIO. 我当前的解决方法是将主体存储在视图中request.auth并自己在视图中解析它,这有效但很丑陋。
有没有办法在 中安全地访问请求正文Authentication?
这是有效的版本:
在myapp/authentications.py:
import hmac
from hashlib import sha1
from rest_framework.authentication import BaseAuthentication
from rest_framework.exceptions import AuthenticationFailed
class WebhookAuthentication(BaseAuthentication):
def authenticate(self, request):
actual_signature = request.META['X-Vendor-Signature']
body, expected_signature = self.expected_signature(request)
if actual_signature != expected_signature:
raise AuthenticationFailed("Request X-Vendor-Signature did not match expected signature")
return None, body # Hack: preserve the …Run Code Online (Sandbox Code Playgroud) rspec ×3
php ×2
ruby ×2
browserify ×1
c# ×1
capybara ×1
django ×1
docker ×1
dockerhub ×1
doctrine-orm ×1
factory-bot ×1
heroku ×1
interface ×1
interface-segregation-principle ×1
javascript ×1
jshint ×1
lint ×1
python ×1
python-2.7 ×1
reactjs ×1
rspec-rails ×1
rspec3 ×1
single-responsibility-principle ×1
soft-delete ×1
state ×1